Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. StackView element is shown again even if it's popped and hidden
Forum Updated to NodeBB v4.3 + New Features

StackView element is shown again even if it's popped and hidden

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 460 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mark81
    wrote on last edited by
    #1

    I'm surely missing something obvious.
    I have this Item called viewWelcome.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:

    1. on startup viewWelcome is the first item on the StackView
    2. 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?

    J.HilkJ 1 Reply Last reply
    0
    • M Mark81

      I'm surely missing something obvious.
      I have this Item called viewWelcome.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:

      1. on startup viewWelcome is the first item on the StackView
      2. 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?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @Mark81 don't set an initial item, those can't be popped


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      M 1 Reply Last reply
      0
      • J.HilkJ J.Hilk

        @Mark81 don't set an initial item, those can't be popped

        M Offline
        M Offline
        Mark81
        wrote on last edited by
        #3

        @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?

        M J.HilkJ 2 Replies Last reply
        0
        • M Mark81

          @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?

          M Offline
          M Offline
          Mark81
          wrote on last edited by
          #4

          @Mark81 Tried but nothing has changed:

          Component {
              id: fooItem
          
              Rectangle {
                  color: "black";
              }
          }
          

          set as initialItem, then:

          Component.onCompleted: stackView.push(viewWelcome)
          

          but when the application quits, I see again for a while viewWelcome

          1 Reply Last reply
          0
          • M Mark81

            @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?

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @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?


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved