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

Layout issues involving Layout.fillWidth/Layout.fillHeight where no implicitHeight is set

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P3: Somewhat important
    • None
    • 5.6.0
    • Quick: Layouts
    • None

    Description

      These two issues might be related somehow.

      The first one is a very simplified version of what Qt Virtual Keyboard does; it has several RowLayout s in a ColumnLayout. I stripped it down as much as possible so that it would reflect QTBUG-54953.

      import QtQuick 2.6
      import QtQuick.Layouts 1.1
      import QtQuick.Window 2.2
      
      Window {
          visible: true
          width: 600
          height: 400
          id: root
      
          Component.onCompleted: {
              x = 500;
              y = 100;
          }
      
          Shortcut {
              sequence: "Ctrl+Q"
              onActivated: Qt.quit()
          }
      
          ColumnLayout {
              anchors.fill: parent
              anchors.topMargin: parent.height / 2
              spacing: 0
      
              Rectangle {
                  color: "green"
                  opacity: 0.2
      
                  Layout.fillWidth: true
                  Layout.fillHeight: true
      
                  onImplicitHeightChanged: print("implicitHeight of green rectangle changed to", implicitHeight)
      
                  Component.onCompleted: print("implicitHeight of green rectangle at completion is", implicitHeight)
              }
      
              RowLayout {
                  spacing: 0
      
                  Rectangle {
                      id: hiddenRect
                      color: "red"
                      opacity: 0.2
                      visible: false
      
                      Layout.fillWidth: true
                      Layout.fillHeight: true
      
                      onImplicitHeightChanged: print("implicitHeight of red rectangle changed to", implicitHeight)
      
                      Component.onCompleted: print("implicitHeight of red rectangle at completion is", implicitHeight)
                  }
              }
          }
      
          MouseArea {
              anchors.horizontalCenter: parent.horizontalCenter
              width: 100
              height: 40
      
              Rectangle {
                  anchors.fill: parent
                  color: "transparent"
                  border.color: "black"
              }
      
              onClicked: {
                  print("making red rectangle visible")
                  hiddenRect.visible = !hiddenRect.visible
              }
      
              Text {
                  text: "Toggle"
                  anchors.centerIn: parent
              }
          }
      }
      

      I ended up with the second example after further stripping down the first one. When made visible, the red rectangle should take up half of the ColumnLayout, but takes up no space at all. Giving an implicit height of 1 to the green rectangle is enough to work around the issue.

      import QtQuick 2.6
      import QtQuick.Layouts 1.1
      import QtQuick.Window 2.2
      
      Window {
          visible: true
          width: 600
          height: 400
          id: root
      
          Component.onCompleted: {
              x = 500;
              y = 100;
          }
      
          Shortcut {
              sequence: "Ctrl+Q"
              onActivated: Qt.quit()
          }
      
          ColumnLayout {
              anchors.fill: parent
              anchors.topMargin: parent.height / 2
              spacing: 0
      
              Rectangle {
                  color: "green"
                  opacity: 0.2
      //            implicitHeight: 1
      
                  Layout.fillWidth: true
                  Layout.fillHeight: true
      
                  onImplicitHeightChanged: print("implicitHeight of green rectangle changed to", implicitHeight)
      
                  Component.onCompleted: print("implicitHeight of green rectangle at completion is", implicitHeight)
              }
      
              Rectangle {
                  id: hiddenRect
                  color: "red"
                  opacity: 0.2
                  visible: false
      
                  Layout.fillWidth: true
                  Layout.fillHeight: true
      
                  onImplicitHeightChanged: print("implicitHeight of red rectangle changed to", implicitHeight)
      
                  Component.onCompleted: print("implicitHeight of red rectangle at completion is", implicitHeight)
              }
          }
      
          MouseArea {
              anchors.horizontalCenter: parent.horizontalCenter
              width: 100
              height: 40
      
              Rectangle {
                  anchors.fill: parent
                  color: "transparent"
                  border.color: "black"
              }
      
              onClicked: {
                  print("making red rectangle visible")
                  hiddenRect.visible = !hiddenRect.visible
              }
      
              Text {
                  text: "Toggle"
                  anchors.centerIn: parent
              }
          }
      }
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              smd Jan Arve
              mitch_curtis Mitch Curtis
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes