From 70417e5c891f94c08ef3d43a8d6150fe516c6f9c 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 Change-Id: I35352ac1e6f975e72d5c9638f8520f8ddd1d56ae Reviewed-by: Assam Boudjelthia Reviewed-by: Rami Potinkara (cherry picked from commit 0a017308cca154b6f906c6e143fb33fe109316bc) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit fdf4738be3a941a14a955aa6931ddfee2145ae58) --- 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 33902a3c071..aa5c1280949 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -3554,8 +3554,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();