Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
5.12.7, 5.14.1
-
None
-
Windows 7/10, imx6-Linux, Ubuntu 18.04
Description
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);