aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier De Cannière <[email protected]>2024-03-27 17:19:42 +0100
committerOlivier De Cannière <[email protected]>2024-04-04 10:46:00 +0200
commitbb7ba7667b4cf3565aa1849d08cc71b9ac011e77 (patch)
treea3f499724c7516ed32c42a21ccf3435ecd431f59
parent082634268a4bd23ff08b9a58d4537eaf800b7b84 (diff)
Controls: Bypass bindings when setting x and y in resizeBackground
Using setX() and setY() instead can remove the binding for them. Fixes: QTBUG-120033 Pick-to: 6.7 6.5 6.2 Change-Id: I77fc5360b2d10436b5e258b5f0ceb96b949eccbe Reviewed-by: Ulf Hermann <[email protected]>
-rw-r--r--src/quicktemplates/qquickcontrol.cpp14
-rw-r--r--tests/auto/quickcontrols/controls/data/tst_control.qml30
2 files changed, 42 insertions, 2 deletions
diff --git a/src/quicktemplates/qquickcontrol.cpp b/src/quicktemplates/qquickcontrol.cpp
index d820eac071..72d298d0af 100644
--- a/src/quicktemplates/qquickcontrol.cpp
+++ b/src/quicktemplates/qquickcontrol.cpp
@@ -335,12 +335,22 @@ void QQuickControlPrivate::resizeBackground()
bool changeHeight = false;
if (((!p->widthValid() || !extra.isAllocated() || !extra->hasBackgroundWidth) && qFuzzyIsNull(background->x()))
|| (extra.isAllocated() && (extra->hasLeftInset || extra->hasRightInset))) {
- background->setX(getLeftInset());
+ const auto leftInset = getLeftInset();
+ if (!qt_is_nan(leftInset) && p->x.valueBypassingBindings() != leftInset) {
+ // We bypass the binding here to prevent it from being removed
+ p->x.setValueBypassingBindings(leftInset);
+ p->dirty(DirtyType::Position);
+ }
changeWidth = !p->width.hasBinding();
}
if (((!p->heightValid() || !extra.isAllocated() || !extra->hasBackgroundHeight) && qFuzzyIsNull(background->y()))
|| (extra.isAllocated() && (extra->hasTopInset || extra->hasBottomInset))) {
- background->setY(getTopInset());
+ const auto topInset = getTopInset();
+ if (!qt_is_nan(topInset) && p->y.valueBypassingBindings() != topInset) {
+ // We bypass the binding here to prevent it from being removed
+ p->y.setValueBypassingBindings(topInset);
+ p->dirty(DirtyType::Position);
+ }
changeHeight = !p->height.hasBinding();
}
if (changeHeight || changeWidth) {
diff --git a/tests/auto/quickcontrols/controls/data/tst_control.qml b/tests/auto/quickcontrols/controls/data/tst_control.qml
index 71dcd7645e..a3e65f2b0f 100644
--- a/tests/auto/quickcontrols/controls/data/tst_control.qml
+++ b/tests/auto/quickcontrols/controls/data/tst_control.qml
@@ -467,6 +467,36 @@ TestCase {
}
Component {
+ id: backgroundTest2
+ Button {
+ id: btn
+ width: 100
+ height: 100
+ topInset: 0
+ objectName: ""
+
+ background: Rectangle {
+ id: bg
+ implicitHeight: 80
+ border.color: "red"
+ y: btn.objectName === "aaa" ? 20 : 0
+ }
+ }
+ }
+
+ // QTBUG-120033: Make sure that the binding for y on the tab button's background doesn't get removed
+ function test_background2() {
+ let button = createTemporaryObject(backgroundTest2, testCase)
+ verify(button)
+
+ verify(button.background.y === 0)
+ button.objectName = "aaa"
+ verify(button.background.y === 20)
+ button.objectName = ""
+ verify(button.background.y === 0)
+ }
+
+ Component {
id: component2
T.Control {
id: item2