diff options
-rw-r--r-- | src/quicktemplates/qquickcontrol.cpp | 14 | ||||
-rw-r--r-- | tests/auto/quickcontrols/controls/data/tst_control.qml | 30 |
2 files changed, 42 insertions, 2 deletions
diff --git a/src/quicktemplates/qquickcontrol.cpp b/src/quicktemplates/qquickcontrol.cpp index 54ad336a02..3489c2574b 100644 --- a/src/quicktemplates/qquickcontrol.cpp +++ b/src/quicktemplates/qquickcontrol.cpp @@ -354,12 +354,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 37de77467a..4a2bc33b33 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 |