From aeb5165cb639ab682bbb6c5f778d53c9746c01ae Mon Sep 17 00:00:00 2001 From: Andreas Buhr Date: Mon, 23 Nov 2020 13:54:37 +0100 Subject: 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 Reviewed-by: Sona Kurazyan --- tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp | 11 ++++++++--- 1 file 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 -- cgit v1.2.3