Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-85405

Invisible Column/Layout is not recalculated when contents become invisible

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.12.3, 5.15.0
    • Quick: Layouts
    • None
    • macOS 10.14.6, Qt 5.15.0, Qt 5.12.3, Qt 5.9.8
    • macOS

    Description

      When a Column or ColumnLayout is not visible, making content items not visible keeps the positioner/layout size unchanged until it becomes visible again. This is a problem when parent or root view is made invisible, the declarative layout does not work as expected.

      Reproduction steps:

      1. Run the attached code
      2. Click right button twice to make button invisible and visible
      3. (Observe layout changes)
      4. Click left button to make column invisible
      5. Click right button to make button invisible
      6. Click left button to make column visible

      Expected:

      Column should have no height

      Actual:

      Columne has height of invisible button

      Reproduction:

      Always

      Workaround:

      Change button width or height to 0 when invisible

       

      import QtQuick 2.9
      import QtQuick.Window 2.0
      import QtQuick.Controls 1.0
      import QtQuick.Layouts 1.0
      
      Window {
          visible: true
          width: 640
          height: 320
          title: qsTr("Buttonmind")
      
          property bool buttonVisible: true
      
          Button {
              id: hideAndSeek
              width: 150
              anchors.left: parent.left
              text: "Show/hide Column"
              onClicked: layout.visible = !layout.visible
          }
          Text {
              anchors {
                  top: hideAndSeek.bottom
                  topMargin: 5
                  horizontalCenter: hideAndSeek.horizontalCenter
              }
              text: layout.visible ? "Layout visible" : "Layout hidden"
          }
      
          Button {
              id: buttonToggler
              anchors.right: parent.right
              width: 150
              text: "Show/hide Button"
              onClicked: buttonVisible = !buttonVisible
          }
          Text {
              anchors {
                  top: buttonToggler.bottom
                  topMargin: 5
                  horizontalCenter: buttonToggler.horizontalCenter
              }
              text: buttonVisible ? "Button visible" : "Button hidden"
          }
      
          Column
          {
              id: layout
              visible: true
              anchors {
                  horizontalCenter: parent.horizontalCenter
                  top: parent.top
                  topMargin: 50
              }
               Button {
                  id: button
                  width: 150 // workaround: visible ? 150 : 0
                  text: "Button"
                  visible: buttonVisible
                  onClicked: buttonVisible = !buttonVisible
              }
          }
          Rectangle {
              anchors.fill: layout
              color: "transparent"
              border {
                  width: 2
                  color: "green"
              }
          }
          Rectangle {
              anchors {
                  top: layout.bottom
                  topMargin: 5
                  horizontalCenter: layout.horizontalCenter
              }
              width: 250
              height: 30
              color: "grey"
      
              Text {
                  anchors.centerIn: parent
                  color: "white"
                  text: "Green rectangle anchors to Column"
              }
          }
      }
      
      

      Attachments

        1. main.qml
          2 kB
          Pavol Markovic

        Issue Links

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              pavol.markovic Pavol Markovic
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: