According to the Qt docs I should be able to call:
Item replace(target, item, properties, operation)
Replaces one or more items on the stack with the specified item and operation, and optionally applies a set of properties on the item. The item can be an Item, Component, or a url. Returns the item that became current.
So if I were to enact:
stackView.replace(stackView.get(stackView.depth - 3), mycomponent)
I would expect the item, located at the stackView index 2 less than the largest index, to replace with mycomponent
. However, this is not the case; it seems that index depth - 1
and depth - 2
and depth - 3
are popped off the stack, then an instance of mycomponent
is added. How do I replace index of depth - 3
without losing the higher-stacked objects?
MVP:
In the following code, if I push
, push
, push
, then replace
, I would expect Depth at onCompleted: 4
to be the value for Current Index: 1
. Instead, I get Depth at onCompleted: 2
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
Window {
visible: true
width: 640
height: 480
id: window
Component {
id: mycomponent
Row {
spacing: 2
Button {
text: "Push"
onClicked: push(mycomponent)
}
Button {
text: "Pop"
onClicked: pop()
}
Button {
text: "Replace"
onClicked: stackView.replace(stackView.get(stackView.depth - 3), mycomponent)
}
Text {
text: "Current Index: " + (stackView.depth - 1)
}
Text {
Component.onCompleted: text = "Depth at onCompleted: " + stackView.depth
}
}
}
StackView {
id: stackView
initialItem: mycomponent
}
}