aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSanthosh Kumar <[email protected]>2025-10-08 14:10:08 +0200
committerSanthosh Kumar <[email protected]>2025-10-12 13:54:41 +0200
commitf41f0607b2df21f979b3a5e5fc866abf9bf488b7 (patch)
tree0c8d4b9536b7c4034fdb2829425939c18c145826
parentb4a207af6943f63e598aee0a74c102a14cf26b71 (diff)
Provide effective size policy of Layout in its attached properties
The QML Layout, by default, has an effective size policy for shrinking and expanding. But its attached properties (Layout.fillHeight/Layout.fillWidth) don't reflect the same. This patch provides an effective size policy of the Layout in its corresponding attached properties (Layout.fillWidth/Layout.fillHeight), and the same has been updated in the documentation. Fixes: QTBUG-139699 Pick-to: 6.10 6.8 6.5 Change-Id: I133fc8161a321678aaeb160aabf3065112dea32a Reviewed-by: Jan Arve Sæther <[email protected]>
-rw-r--r--src/quicklayouts/qquicklayout.cpp4
-rw-r--r--src/quicklayouts/qquicklayout_p.h18
-rw-r--r--tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml8
3 files changed, 24 insertions, 6 deletions
diff --git a/src/quicklayouts/qquicklayout.cpp b/src/quicklayouts/qquicklayout.cpp
index 97219a1daa..4185f43aa0 100644
--- a/src/quicklayouts/qquicklayout.cpp
+++ b/src/quicklayouts/qquicklayout.cpp
@@ -308,6 +308,8 @@ void QQuickLayoutAttached::setMaximumImplicitSize(const QSizeF &sz)
set to the preferred width.
The default depends on implicit (built-in) size policy of item.
+ \note By default, this property is \c true for layouts.
+
\sa fillHeight
*/
void QQuickLayoutAttached::setFillWidth(bool fill)
@@ -329,6 +331,8 @@ void QQuickLayoutAttached::setFillWidth(bool fill)
set to the preferred height.
The default depends on implicit (built-in) size policy of the item.
+ \note By default, this property is \c true for layouts.
+
\sa fillWidth
*/
void QQuickLayoutAttached::setFillHeight(bool fill)
diff --git a/src/quicklayouts/qquicklayout_p.h b/src/quicklayouts/qquicklayout_p.h
index 971862a145..c75e4e6103 100644
--- a/src/quicklayouts/qquicklayout_p.h
+++ b/src/quicklayouts/qquicklayout_p.h
@@ -221,21 +221,27 @@ public:
void setMaximumImplicitSize(const QSizeF &sz);
bool fillWidth() const {
- if (auto *itemPriv = itemForSizePolicy(m_isFillWidthSet)) {
+ bool effectiveFillWidth = m_fillWidth;
+ if (!m_isFillWidthSet && qobject_cast<QQuickLayout *>(item())) {
+ effectiveFillWidth = true;
+ } else if (auto *itemPriv = itemForSizePolicy(m_isFillWidthSet)) {
QLayoutPolicy::Policy hPolicy = itemPriv->sizePolicy().horizontalPolicy();
- return hPolicy & QLayoutPolicy::GrowFlag;
+ effectiveFillWidth = (hPolicy & QLayoutPolicy::GrowFlag);
}
- return m_fillWidth;
+ return effectiveFillWidth;
}
void setFillWidth(bool fill);
bool isFillWidthSet() const { return m_isFillWidthSet; }
bool fillHeight() const {
- if (auto *itemPriv = itemForSizePolicy(m_isFillHeightSet)) {
+ bool effectiveFillHeight = m_fillHeight;
+ if (!m_isFillHeightSet && qobject_cast<QQuickLayout *>(item())) {
+ effectiveFillHeight = true;
+ } else if (auto *itemPriv = itemForSizePolicy(m_isFillHeightSet)) {
QLayoutPolicy::Policy vPolicy = itemPriv->sizePolicy().verticalPolicy();
- return vPolicy & QLayoutPolicy::GrowFlag;
+ effectiveFillHeight = (vPolicy & QLayoutPolicy::GrowFlag);
}
- return m_fillHeight;
+ return effectiveFillHeight;
}
void setFillHeight(bool fill);
bool isFillHeightSet() const { return m_isFillHeightSet; }
diff --git a/tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml b/tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml
index 56198f0d2e..cb61c6c31a 100644
--- a/tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml
+++ b/tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml
@@ -100,6 +100,14 @@ Item {
}
}
+ function test_defaultSizePolicyForLayout() {
+ var layout = layout_columnLayout_Component.createObject(container)
+ waitForRendering(layout)
+ compare(layout.Layout.fillWidth, true)
+ compare(layout.Layout.fillHeight, true)
+ layout.destroy()
+ }
+
function test_warnAboutLayoutItemsWithAnchors()
{
var regex = new RegExp(".*: Detected anchors on an item that is managed by a layout. "