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. Change-Id: I18f6de356ea20f4744f3a58cd2b1d76f6a9545a4 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io> (cherry picked from commit aeb5165cb639ab682bbb6c5f778d53c9746c01ae) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
f19d84f048
commit
51d047f9a9
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user