diff --git a/src/layouts/qquickgridlayoutengine.cpp b/src/layouts/qquickgridlayoutengine.cpp index 7935d79c453e99c4ac4f10a91b988f06954530c8..e734e9fef84d9ef6d7cf650a6ae7eccd9a84df23 100644 --- a/src/layouts/qquickgridlayoutengine.cpp +++ b/src/layouts/qquickgridlayoutengine.cpp @@ -182,24 +182,26 @@ Fixed | Layout.fillWidth | Expanding if layout, Fixed if item | we only want to use the initial width. This is because the width will change due to layout rearrangement, and the preferred width should return the same value, regardless of the current width. - We therefore store the width in the Layout.preferredWidth attached property. - Since the layout listens to changes of Layout.preferredWidth, (it will - basically cause an invalidation of the layout, we have to disable that - notification while we set the preferred width. + We therefore store the width in the implicitWidth attached property. + Since the layout listens to changes of implicitWidth, (it will + basically cause an invalidation of the layout), we have to disable that + notification while we set the implicit width (and height). Only use this fallback the first time the size hint is queried. Otherwise, we might end up picking a width that is different than what was specified in the QML. */ - const bool was = info->setChangesNotificationEnabled(false); - if (prefWidth < 0) { - prefWidth = item->width(); - info->setPreferredWidth(prefWidth); + if (prefWidth < 0 || prefHeight < 0) { + item->blockSignals(true); + if (prefWidth < 0) { + prefWidth = item->width(); + item->setImplicitWidth(prefWidth); + } + if (prefHeight < 0) { + prefHeight = item->height(); + item->setImplicitHeight(prefHeight); + } + item->blockSignals(false); } - if (prefHeight < 0) { - prefHeight = item->height(); - info->setPreferredHeight(prefHeight); - } - info->setChangesNotificationEnabled(was); } //--- GATHER MAXIMUM SIZE HINTS --- // They are always q_declarativeLayoutMaxSize diff --git a/tests/auto/controls/data/tst_rowlayout.qml b/tests/auto/controls/data/tst_rowlayout.qml index d142a596556d42bf264022bd5d26e07a0e019415..1b9573e0c4d17b387f9dabe262ae9eace69ee26c 100644 --- a/tests/auto/controls/data/tst_rowlayout.qml +++ b/tests/auto/controls/data/tst_rowlayout.qml @@ -262,6 +262,7 @@ Item { Component { id: columnLayoutItem_Component ColumnLayout { + spacing: 0 } } @@ -295,7 +296,8 @@ Item { rect3.Layout.fillHeight = true compare(layout.implicitWidth, 70) - compare(layout.implicitHeight, 30) + compare(col.implicitHeight, 40) + compare(layout.implicitHeight, 40) rect3.destroy() wait(0) // this will hopefully effectuate the destruction of the object