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

RowLayout sets explicit height to 0 if implicitHeight is not set

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: Not Evaluated Not Evaluated
    • None
    • 5.12.7, 5.14.1
    • None
    • Windows 7/10, imx6-Linux, Ubuntu 18.04
    • Linux/Wayland, Linux/Yocto, Windows

       

      In the following example the rectangle 'myRec' will be drawn with the height '0' after the implicitWidth has changed at runtime.

      import QtQuick 2.9
      import QtQuick.Window 2.3
      import QtQuick.Layouts 1.3
      Window {
          visible: true
          width: 300
          height: 200
          title: qsTr("Hello World")
          RowLayout {
             anchors.fill: parent
              Rectangle {
                  id: myRec
                  border.color: "red"
                  color: "grey"
                  Layout.fillWidth: true
                  height: 50
                  implicitWidth: myTxt.implicitWidth
                  // fix 1:
                  // Layout.preferredHeight: height
                  // fix 2:
                  // implicitHeight: height
                  // fix 3: override implicitWidth
                  // implicitWidth: 0
                  Text {
                      id: myTxt
                  }
              }
          }
          Timer {
              interval: 500
              repeat: true
              running: true
              onTriggered: {
                  if(myTxt.text === "ABC")
                      myTxt.text = "0"
                  else
                      myTxt.text = "ABC"
              }
          }
      }
      

      The bug doesn't occur if the implicitHeight or Layout.preferredHeight is set.

       

      Nonetheless the following patch fixes the issue in the qtdeclarative package  by using the fallbackHeight if the prefHeight isn't set: 

       

      diff --git a/src/imports/layouts/qquicklayout.cpp b/src/imports/layouts/qquicklayout.cpp
      index 17d37b5c..8c679ace 100644
      --- a/src/imports/layouts/qquicklayout.cpp
      +++ b/src/imports/layouts/qquicklayout.cpp
      @@ -1110,6 +1110,14 @@ void QQuickLayout::effectiveSizeHints_helper(QQuickItem *item, QSizeF *cachedSiz
               updatePreferredSizes(prefWidth, info->m_fallbackWidth, item->width());
               updatePreferredSizes(prefHeight, info->m_fallbackHeight, item->height());
           }
      +    else
      +    if(info)
      +    {
      +        if (prefWidth < 0 && info->m_fallbackWidth > 0)
      +            prefWidth = info->m_fallbackWidth;
      +        if (prefHeight < 0 && info->m_fallbackHeight > 0)
      +            prefHeight = info->m_fallbackHeight;
      +    }
       
           // Normalize again after the implicit hints have been gathered
           expandSize(prefS, minS);
      
      

       

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

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            prueckl thomas
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes