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. How to make StackLayout collapse when currentIndex === -1?

How to make StackLayout collapse when currentIndex === -1?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 3 Posters 434 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.
  • K Offline
    K Offline
    Kamichanw
    wrote on last edited by
    #1

    The following code just do a simple thing: change the currentIndex of StackLayout to -1 when clicked. But I want to let the height of StackLayout to be 0 when currentIndex is -1.

    Window {
        id: window
        width: 400
        height: 400
        visible: true
        color: "#181818"
        MouseArea {
            id: ma
            anchors.fill: parent
            hoverEnabled: true
            onClicked: lay.currentIndex = -1
        }
    
        StackLayout {
            id: lay
            anchors.top: parent.top
            Rectangle {
                width: 300
                height: 100
                color: "white"
            }
        }
        Rectangle {
            anchors.top: lay.bottom
            width: 200
            height: 100
            color: "red"
        }
    }
    

    I've tried Binding like

    Binding {
        when: lay.currentIndex === -1
        lay.height: 0
    }
    

    But this won't work.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Shouldn't you rather make it invisible ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      K 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Shouldn't you rather make it invisible ?

        K Offline
        K Offline
        Kamichanw
        wrote on last edited by
        #3

        @SGaist Hi,
        But set it invisible won't make StackLayout collapse.

        SGaistS 1 Reply Last reply
        0
        • K Kamichanw

          @SGaist Hi,
          But set it invisible won't make StackLayout collapse.

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Do you mean you want to animate its size going down to 0 ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          K 1 Reply Last reply
          0
          • SGaistS SGaist

            Do you mean you want to animate its size going down to 0 ?

            K Offline
            K Offline
            Kamichanw
            wrote on last edited by
            #5

            @SGaist No, I hope the StackLayout can be folded when currentIndex === -1

            L 1 Reply Last reply
            0
            • K Kamichanw

              @SGaist No, I hope the StackLayout can be folded when currentIndex === -1

              L Offline
              L Offline
              lemons
              wrote on last edited by
              #6

              @Kamichanw I don't get what you want to achieve, but I assume you can simply bind the height?

              StackLayout {
                  id: lay
                  anchors.top: parent.top
                  height: currentIndex >= 0 ? childrenRect.height : 0
                  Rectangle {
                      width: 300
                      height: 100
                      color: "white"
                  }
              }
              
              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