From 0a017308cca154b6f906c6e143fb33fe109316bc Mon Sep 17 00:00:00 2001 From: Bartlomiej Moskal Date: Wed, 15 Jan 2025 22:24:42 +0100 Subject: [PATCH] Android: Unblacklist textMargin test from tst_QLineEdit Older devices may have lower screen resolution. In this case, the hardcoded width may not work as expected. For example, all text may not fit in QLineEdit. This was the reason why the tst_qlineedit::textMargin test failed on some Android devices (especially x86 emulator with Android API 29). When the left and right margins were set to 20, all tested text did not fit in QLineEdit. When we clicked at the beginning of QLineEdit, we clicked on the second character of the text. The cursor was moved to position 1, which caused the test to fail. This commit updates textMargin test to make sure that tested text will fit in to the QLineEdit. Task-number: QTBUG-87417 Fixes: QTQAINFRA-6897 Pick-to: 6.9 6.8 Change-Id: I35352ac1e6f975e72d5c9638f8520f8ddd1d56ae Reviewed-by: Assam Boudjelthia Reviewed-by: Rami Potinkara --- tests/auto/widgets/widgets/qlineedit/BLACKLIST | 2 -- tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/auto/widgets/widgets/qlineedit/BLACKLIST b/tests/auto/widgets/widgets/qlineedit/BLACKLIST index 57d56b56692..fa2fc7eaa3c 100644 --- a/tests/auto/widgets/widgets/qlineedit/BLACKLIST +++ b/tests/auto/widgets/widgets/qlineedit/BLACKLIST @@ -1,5 +1,3 @@ # QTBUG-87417 -[textMargin] -android [testQuickSelectionWithMouse] android diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index 8c129e748d5..c7a78511dbe 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -3555,8 +3555,10 @@ void tst_QLineEdit::textMargin() // resizing by the window system. QWidget tlw; QLineEdit testWidget(&tlw); - testWidget.setGeometry(100, 100, 100, 30); testWidget.setText("MMM MMM MMM"); + QFontMetrics metrics(testWidget.font()); + const int minimumWidth = metrics.horizontalAdvance(testWidget.text()); + testWidget.setGeometry(100, 100, qMax(minimumWidth, 100) , 30); testWidget.setCursorPosition(6); QSize sizeHint = testWidget.sizeHint();