StackView not behaving as expected
-
Hi all -
I'm trying to implement a StackView, but it's not working as I'd expect. Here's the code:
import QtQuick import QtQuick.Controls import QtQuick.Layouts ApplicationWindow { width: 640 height: 480 visible: true StackView { id: stack anchors.fill: parent } Component { id: activity Rectangle { color: 'blue' MouseArea { anchors.fill: parent onClicked: { console.log("clicked!") stack.pop() } } } } Button { onClicked: stack.push(activity) text: "push to push" } }Two things are happening that I don't expect:
- the pushed Component doesn't hide what's underneath it -- shouldn't it?
- clicking in the Component doesn't cause the pop to occur -- the Rectangle remains visible.
Any suggestions are appreciated.
Thanks...
-
@mzimmers said in StackView not behaving as expected:
import QtQuick
import QtQuick.Controls
import QtQuick.LayoutsApplicationWindow {
width: 640
height: 480
visible: trueStackView { id: stack anchors.fill: parent } Component { id: activity Rectangle { color: 'blue' MouseArea { anchors.fill: parent onClicked: { console.log("clicked!") stack.pop() } } } } Button { onClicked: stack.push(activity) text: "push to push" }}
the pushed Component doesn't hide what's underneath it -- shouldn't it?
StackView is empty at the beginning. If one item is pushed into it, there is only one item and it will be displayed. I guess it is normal.clicking in the Component doesn't cause the pop to occur -- the Rectangle remains visible.
stack.clear() will work. Try to add two components to see if pop() works. -
@mzimmers said in StackView not behaving as expected:
import QtQuick
import QtQuick.Controls
import QtQuick.LayoutsApplicationWindow {
width: 640
height: 480
visible: trueStackView { id: stack anchors.fill: parent } Component { id: activity Rectangle { color: 'blue' MouseArea { anchors.fill: parent onClicked: { console.log("clicked!") stack.pop() } } } } Button { onClicked: stack.push(activity) text: "push to push" }}
the pushed Component doesn't hide what's underneath it -- shouldn't it?
StackView is empty at the beginning. If one item is pushed into it, there is only one item and it will be displayed. I guess it is normal.clicking in the Component doesn't cause the pop to occur -- the Rectangle remains visible.
stack.clear() will work. Try to add two components to see if pop() works.@JoeCFD yeah, I did that and it works better now. Evidently a pushed StackView item will only hide another StackView item.
Thanks for looking.
EDIT:
For anyone interested, here's the two component example that works:
import QtQuick import QtQuick.Controls import QtQuick.Layouts ApplicationWindow { width: 640 height: 480 visible: true StackView { id: stack anchors.fill: parent initialItem: mainArea } Component { id: activity Rectangle { color: 'blue' Button { onClicked: { console.log("popped!") stack.pop() } text: "push to pop" } } } Component { id: mainArea Rectangle { Button { onClicked: stack.push(activity) text: "push to push" } } } }