diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2024-03-22 10:50:01 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2024-04-11 23:20:21 +0100 |
commit | f1521d3723ae9c1e899b1dffde74a027c88a151e (patch) | |
tree | 54fa34680afccb4bcaf37a5ecf27acde6a97f73e /tests | |
parent | fb4df47aab7cd9816e1eb1c98a8e554e37cbcee3 (diff) |
Loader: keep control over resizing
A Loader with an explicitly set size is supposed to control its child's
size. However, so far, we would have kept bindings on width and height
in place - before Qt 6.2 in any case, since 6.2 (and the change to make
Item's geometry properties bindable) only when both size and width
change at the same time. Thus, if the binding was triggered afterwards,
it would have overridden the size set by the Loader.
Fix this by always removing installed bindings.
Fixes: QTBUG-117641
Pick-to: 6.7
Change-Id: Iece4d90bacd9e16a07e5018bf11fa0f7ba9c84df
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquickloader/data/Rect120x60.qml | 8 | ||||
-rw-r--r-- | tests/auto/quick/qquickloader/tst_qquickloader.cpp | 38 |
2 files changed, 40 insertions, 6 deletions
diff --git a/tests/auto/quick/qquickloader/data/Rect120x60.qml b/tests/auto/quick/qquickloader/data/Rect120x60.qml index fc9e447e69..6a0bb3d766 100644 --- a/tests/auto/quick/qquickloader/data/Rect120x60.qml +++ b/tests/auto/quick/qquickloader/data/Rect120x60.qml @@ -1,6 +1,10 @@ import QtQuick 2.0 Rectangle { - width: 120 - height:60 + property int base: 60 + property int w: base*2 + property int h: base + property int ignore: 0 + width: w + height: h } diff --git a/tests/auto/quick/qquickloader/tst_qquickloader.cpp b/tests/auto/quick/qquickloader/tst_qquickloader.cpp index 0934a05b54..26dfd595cd 100644 --- a/tests/auto/quick/qquickloader/tst_qquickloader.cpp +++ b/tests/auto/quick/qquickloader/tst_qquickloader.cpp @@ -64,6 +64,7 @@ private slots: void componentToUrl(); void anchoredLoader(); void sizeLoaderToItem(); + void sizeItemToLoader_data(); void sizeItemToLoader(); void noResize(); void networkRequestUrl(); @@ -378,8 +379,29 @@ void tst_QQuickLoader::sizeLoaderToItem() QCOMPARE(rect->height(), 30.0); } +void tst_QQuickLoader::sizeItemToLoader_data() +{ + QTest::addColumn<QString>("property"); + QTest::addColumn<int>("value"); + QTest::addColumn<bool>("atOnce"); + + QTest::addRow("none_atonce") << "ignore" << 42 << true; + QTest::addRow("width_atonce") << "w" << 42 << true; + QTest::addRow("height_atonce") << "h" << 42 << true; + QTest::addRow("both_atonce") << "both" << 42 << true; + + + QTest::addRow("none") << "ignore" << 42 << false; + QTest::addRow("width") << "w" << 42 << false; + QTest::addRow("height") << "h" << 42 << false; + QTest::addRow("both") << "both" << 42 << false; +} + void tst_QQuickLoader::sizeItemToLoader() { + QFETCH(QString, property); + QFETCH(int, value); + QFETCH(bool, atOnce); QQmlEngine engine; QQmlComponent component(&engine, testFileUrl("/SizeToLoader.qml")); QScopedPointer<QQuickLoader> loader(qobject_cast<QQuickLoader*>(component.create())); @@ -389,17 +411,25 @@ void tst_QQuickLoader::sizeItemToLoader() QQuickItem *rect = qobject_cast<QQuickItem*>(loader->item()); QVERIFY(rect); + rect->setProperty(property.toUtf8(), value); QCOMPARE(rect->width(), 200.0); QCOMPARE(rect->height(), 80.0); // Check resize QSizeChangeListener sizeListener(rect); const QSizeF size(180, 30); - loader->setSize(size); + if (atOnce) { + loader->setSize(size); + } else { + loader->setWidth(size.width()); + loader->setHeight(size.height()); + } QVERIFY2(!sizeListener.isEmpty(), "There should be at least one signal about the size changed"); - for (const QSizeF sizeOnGeometryChanged : sizeListener) { - // Check that we have the correct size on all signals - QCOMPARE(sizeOnGeometryChanged, size); + if (atOnce) { + for (const QSizeF sizeOnGeometryChanged : sizeListener) { + // Check that we have the correct size on all signals + QCOMPARE(sizeOnGeometryChanged, size); + } } QCOMPARE(rect->width(), size.width()); QCOMPARE(rect->height(), size.height()); |