Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. StackView not behaving as expected
Qt 6.11 is out! See what's new in the release blog

StackView not behaving as expected

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 600 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    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:

    1. the pushed Component doesn't hide what's underneath it -- shouldn't it?
    2. clicking in the Component doesn't cause the pop to occur -- the Rectangle remains visible.

    Any suggestions are appreciated.

    Thanks...

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      @mzimmers said in StackView not behaving as expected:

      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"
      }
      

      }

      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.

      mzimmersM 1 Reply Last reply
      1
      • JoeCFDJ JoeCFD

        @mzimmers said in StackView not behaving as expected:

        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"
        }
        

        }

        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.

        mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by mzimmers
        #3

        @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"
                    }
                }
            }
        }
        
        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