StackView element is shown again even if it's popped and hidden
-
I'm surely missing something obvious.
I have thisItem
calledviewWelcome.qml
:import QtQuick 2.0 import QtMultimedia Item { id: root signal ended() Component.onCompleted: { mediaBackground.play(); } Image { id: imgLogo anchors.centerIn: parent source: "qrc:/icons/Logo.png" rotation: -90 width: parent.height * 0.7 fillMode: Image.PreserveAspectFit } MediaPlayer { id: mediaBackground videoOutput: videoOutput source: "file:///mnt/resources/themes/default/demo.mp4" onMediaStatusChanged: { if (mediaStatus === MediaPlayer.EndOfMedia) { // all my tries to hide the elements root.visible = false root.opacity = 0.0 mediaBackground.source = "" videoOutput.visible = false videoOutput.opacity = 0.0 imgLogo.source = "" ended() } } } VideoOutput { id: videoOutput anchors.centerIn: parent anchors.horizontalCenterOffset: 700 anchors.verticalCenterOffset: -200 width: 1080 * 0.5 height: 1920 rotation: -90 fillMode: VideoOutput.PreserveAspectFit } }
Then in my
main.qml
:import QtQuick import QtQuick.Controls import QtMultimedia import Qt5Compat.GraphicalEffects ApplicationWindow { id: window objectName: "window" width: 1920 height: 1080 visible: true visibility: "FullScreen" color: "black" Item { id: item anchors.fill: parent StackView { id: stack anchors.fill: parent initialItem: viewWelcome } PageWelcome { id: viewWelcome onEnded: { stack.pop() stack.push(viewContent) // try to hide it one more time... viewWelcome.visible = false viewWelcome.opacity = 0.0 } } Content { id: viewContent // some stuff } } }
So basically the behavior is the following:
- on startup
viewWelcome
is the first item on theStackView
- then the video ends, the item is popped and another one is pushed onto the stack
Great!
The problem is whenever I pop/push something else, or even when I quit the application, the initial item appears for a fraction of second. It's very annoying because I set all the available properties I know to hide that! And it's popped from the stack...What can cause this behavior?
- on startup
-
@J-Hilk are you sure? I can't find this information in the docs:
initialItem : var
This property holds the initial item that should be shown when the StackView is created. The initial item can be an Item, Component, or a url. Specifying an initial item is equivalent to:
Component.onCompleted: stackView.push(myInitialItem)In fact, even pushing the first item manually:
Component.onCompleted: stackView.push(viewWelcome)
the behavior is the same.
Or are you suggesting the FIRST item cannot be popped? Hence I need to push a fake item with a black background? -
-
@Mark81 said in StackView element is shown again even if it's popped and hidden:
Or are you suggesting the FIRST item cannot be popped? Hence I need to push a fake item with a black background?
yes, I had to do that, in one of my apps, or I would end up with multiple instances of a Bluetooth module, because one was never going destroyed even though I popped it, removing the initial item and using a push on construction fixed it for me. But it doesn't seem to fix it for you
can you give a minimal reproducible example for us to look at?