aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2018-12-14 12:08:48 +0100
committerMitch Curtis <mitch.curtis@qt.io>2018-12-21 12:01:23 +0000
commitb563bd583a50442b52e47f8c5f149aebafb385f2 (patch)
treeee6347d0c2894309b8b2b2299de7901b59123dd5 /tests/auto
parent69f02184a9a71f3a5e2dd1ada12367ddccd29787 (diff)
Fix TextField background not respecting control's width
After 6858d4e9, the background of the Material style TextField does not respect the width of the control if the control is resized (e.g. due to being in a layout). - The first time resizeBackground() is called, !extra.isAllocated() returns true - that is, extra has not been allocated yet. - The if statement is executed and the background's width is set to the available width of the control (e.g. 120). - As a result of the background's width being set, its widthValid flag is set to true. This would previously be undone directly afterwards by setting widthValid flag to false. - In the case of the test case, the implicitWidth was already 120, so geometryChanged is not emitted. However, when the height of the background is set, this *does* cause itemGeometryChanged() to be called, which in turn does the following: extra.value().hasBackgroundWidth = p->widthValid; extra.value().hasBackgroundHeight = p->heightValid; resizeBackground(); So now all of the following checks evaluate to false: (!p->widthValid || !extra.isAllocated() || !extra->hasBackgroundWidth) This prevents the background from being resized. This patch fixes the issue by unsetting the widthValid (and heightValid) flags of the background directly after setting its width. To be safe, it also only unsets it if we were the ones to set it. By doing this, the check mentioned above succeeds because p->widthValid and extra->hasBackgroundWidth are both now false. It also adds some extra safety into itemGeometryChanged() that ensures that extra.value().hasBackgroundWidth is only set if necessary, and therefore prevents the extra data from unnecessarily being allocated. This is not necessary for the fix, but feels like the right thing to do. Change-Id: I051e281718bd8a2a20c100767d929fb71497ce1b Fixes: QTBUG-71875 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/controls/data/tst_textfield.qml27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_textfield.qml b/tests/auto/controls/data/tst_textfield.qml
index ee2d1a54..2ee1db41 100644
--- a/tests/auto/controls/data/tst_textfield.qml
+++ b/tests/auto/controls/data/tst_textfield.qml
@@ -51,6 +51,7 @@
import QtQuick 2.12
import QtTest 1.0
import QtQuick.Controls 2.12
+import QtQuick.Layouts 1.12
TestCase {
id: testCase
@@ -633,4 +634,30 @@ TestCase {
compare(control.background.height, 100)
}
+ Component {
+ id: layoutComponent
+
+ ColumnLayout {
+ anchors.fill: parent
+
+ property alias textField: textField
+
+ TextField {
+ id: textField
+ placeholderText: "Placeholder"
+ Layout.fillWidth: true
+ }
+ }
+ }
+
+ function test_inLayout() {
+ var layout = createTemporaryObject(layoutComponent, testCase)
+ verify(layout)
+
+ var control = layout.textField
+ verify(control)
+
+ compare(control.width, control.parent.width)
+ compare(control.background.width, control.width)
+ }
}