diff options
Diffstat (limited to 'tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp')
-rw-r--r-- | tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index 6408df3f11..7c2203deb4 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -292,6 +292,7 @@ private slots: void clearButtonVisibleAfterSettingText_QTBUG_45518(); void sideWidgets(); void sideWidgetsActionEvents(); + void sideWidgetsEffectiveMargins(); void shouldShowPlaceholderText_data(); void shouldShowPlaceholderText(); @@ -4646,6 +4647,71 @@ void tst_QLineEdit::sideWidgetsActionEvents() QCOMPARE(toolButton2->x(), toolButton1X); } +/*! + Verify that side widgets are positioned correctly and result in + correct effective text margins. +*/ +void tst_QLineEdit::sideWidgetsEffectiveMargins() +{ +#ifndef QT_BUILD_INTERNAL + QSKIP("This test requires a developer build."); +#else + QLineEdit edit; + edit.setPlaceholderText("placeholder"); + edit.setClearButtonEnabled(true); + edit.show(); + QLineEditPrivate *priv = QLineEditPrivate::get(&edit); + const auto sideWidgetParameters = priv->sideWidgetParameters(); + const int sideWidgetWidth = sideWidgetParameters.widgetWidth + sideWidgetParameters.margin; + QVERIFY(QTest::qWaitForWindowExposed(&edit)); + + QCOMPARE(priv->effectiveTextMargins().left(), 0); + QCOMPARE(priv->effectiveTextMargins().right(), 0); + + edit.setText("Left to right"); // clear button fades in on the right + QCOMPARE(priv->effectiveTextMargins().left(), 0); + QCOMPARE(priv->effectiveTextMargins().right(), sideWidgetWidth); + edit.clear(); + QCOMPARE(priv->effectiveTextMargins().left(), 0); + QCOMPARE(priv->effectiveTextMargins().right(), 0); + + edit.setLayoutDirection(Qt::RightToLeft); + edit.setText("ئۇيغۇر تىلى"); // clear button fades in on the left + QCOMPARE(priv->effectiveTextMargins().left(), sideWidgetWidth); + QCOMPARE(priv->effectiveTextMargins().right(), 0); + edit.clear(); + QCOMPARE(priv->effectiveTextMargins().left(), 0); + QCOMPARE(priv->effectiveTextMargins().right(), 0); + + edit.setLayoutDirection(Qt::LeftToRight); + + const QIcon leftIcon = edit.style()->standardIcon(QStyle::SP_FileIcon); + const QIcon rightIcon = edit.style()->standardIcon(QStyle::SP_DirIcon); + edit.addAction(leftIcon, QLineEdit::ActionPosition::LeadingPosition); + QCOMPARE(priv->effectiveTextMargins().left(), sideWidgetWidth); + QCOMPARE(priv->effectiveTextMargins().right(), 0); + + edit.addAction(rightIcon, QLineEdit::ActionPosition::TrailingPosition); + QCOMPARE(priv->effectiveTextMargins().left(), sideWidgetWidth); + QCOMPARE(priv->effectiveTextMargins().right(), sideWidgetWidth); + + edit.setText("Left to right"); // clear button on the right + QCOMPARE(priv->effectiveTextMargins().left(), sideWidgetWidth); + QCOMPARE(priv->effectiveTextMargins().right(), 2 * sideWidgetWidth); + edit.clear(); + QCOMPARE(priv->effectiveTextMargins().left(), sideWidgetWidth); + QCOMPARE(priv->effectiveTextMargins().right(), sideWidgetWidth); + + edit.setLayoutDirection(Qt::RightToLeft); + edit.setText("ئۇيغۇر تىلى"); // clear button fades in on the left + QCOMPARE(priv->effectiveTextMargins().left(), 2 * sideWidgetWidth); + QCOMPARE(priv->effectiveTextMargins().right(), sideWidgetWidth); + edit.clear(); + QCOMPARE(priv->effectiveTextMargins().left(), sideWidgetWidth); + QCOMPARE(priv->effectiveTextMargins().right(), sideWidgetWidth); +#endif +} + Q_DECLARE_METATYPE(Qt::AlignmentFlag) void tst_QLineEdit::shouldShowPlaceholderText_data() { |