summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets
diff options
context:
space:
mode:
authorAndreas Buhr <andreas.buhr@qt.io>2020-11-23 13:54:37 +0100
committerAndreas Buhr <andreas.buhr@qt.io>2020-12-08 15:18:41 +0100
commitaeb5165cb639ab682bbb6c5f778d53c9746c01ae (patch)
tree0ceb6eac5419042fc35fd8dd2f54ee1bb3f8dd71 /tests/auto/widgets/widgets
parentcd661122987826357adb22684c3d953efadee638 (diff)
Fix tst_qlineedit for offscreen rendering and tiling window managers
tst_QLineEdit::QTBUG13520_textNotVisible checks that text is visible if a QLineEdit is set to Qt::AlignRight. To do that, it writes some text into a line edit and checks afterwards that the first character is in the left half of the window. This fails if the window is larger than twice the length of the text used and thus might fail in multiple situations where Qt is not in full control over the size of the windows created, as is the case with tiling window managers. This patch changes the test to not check for the first character in the left half of the window, but instead check for the first character be approximately at the expected position. Pick-to: 6.0 Change-Id: I18f6de356ea20f4744f3a58cd2b1d76f6a9545a4 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'tests/auto/widgets/widgets')
-rw-r--r--tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp11
1 files changed, 8 insertions, 3 deletions
diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
index 6df217d801..a18999d174 100644
--- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
+++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
@@ -4111,13 +4111,18 @@ void tst_QLineEdit::QTBUG13520_textNotVisible()
le.setAlignment( Qt::AlignRight | Qt::AlignVCenter);
le.show();
QVERIFY(QTest::qWaitForWindowExposed(&le));
- le.setText("01-ST16-01SIL-MPL001wfgsdfgsdgsdfgsdfgsdfgsdfgsdfg");
+ QString sometext("01-ST16-01SIL-MPL001wfgsdfgsdgsdfgsdfgsdfgsdfgsdfg");
+ le.setText(sometext);
le.setCursorPosition(0);
QTest::qWait(100); //just make sure we get he lineedit correcly painted
- QVERIFY(le.cursorRect().center().x() < le.width() / 2);
-
+ auto expectedCursorCoordinate = le.width() - le.fontMetrics().horizontalAdvance(sometext);
+ // cursor does not leave widget to the left:
+ if (expectedCursorCoordinate < 0)
+ expectedCursorCoordinate = 0;
+ // compare with some tolerance for margins
+ QVERIFY(qAbs(le.cursorRect().center().x() - expectedCursorCoordinate) < 10);
}
class UpdateRegionLineEdit : public QLineEdit