diff options
-rw-r--r-- | src/widgets/widgets/qlineedit_p.cpp | 8 | ||||
-rw-r--r-- | src/widgets/widgets/qlineedit_p.h | 2 | ||||
-rw-r--r-- | tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp | 45 |
3 files changed, 50 insertions, 5 deletions
diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp index 6a41c3791f..ad3a92d35a 100644 --- a/src/widgets/widgets/qlineedit_p.cpp +++ b/src/widgets/widgets/qlineedit_p.cpp @@ -440,6 +440,10 @@ QWidget *QLineEditPrivate::addAction(QAction *newAction, QAction *before, QLineE Q_Q(QLineEdit); if (!newAction) return 0; + if (!hasSideWidgets()) { // initial setup. + QObject::connect(q, SIGNAL(textChanged(QString)), q, SLOT(_q_textChanged(QString))); + lastTextSize = q->text().size(); + } QWidget *w = 0; // Store flags about QWidgetAction here since removeAction() may be called from ~QAction, // in which a qobject_cast<> no longer works. @@ -456,10 +460,6 @@ QWidget *QLineEditPrivate::addAction(QAction *newAction, QAction *before, QLineE toolButton->setDefaultAction(newAction); w = toolButton; } - if (!hasSideWidgets()) { // initial setup. - QObject::connect(q, SIGNAL(textChanged(QString)), q, SLOT(_q_textChanged(QString))); - lastTextSize = q->text().size(); - } // If there is a 'before' action, it takes preference PositionIndexPair positionIndex = before ? findSideWidget(before) : PositionIndexPair(position, -1); SideWidgetEntryList &list = positionIndex.first == QLineEdit::TrailingPosition ? trailingSideWidgets : leadingSideWidgets; diff --git a/src/widgets/widgets/qlineedit_p.h b/src/widgets/widgets/qlineedit_p.h index 1ede07e4cb..4654262ea7 100644 --- a/src/widgets/widgets/qlineedit_p.h +++ b/src/widgets/widgets/qlineedit_p.h @@ -65,7 +65,7 @@ QT_BEGIN_NAMESPACE // QLineEditIconButton: This is a simple helper class that represents clickable icons that fade in with text -class QLineEditIconButton : public QToolButton +class Q_AUTOTEST_EXPORT QLineEditIconButton : public QToolButton { Q_OBJECT Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity) diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index 9417541040..adedc601a9 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -304,6 +304,7 @@ private slots: void undoRedoAndEchoModes(); void clearButton(); + void clearButtonVisibleAfterSettingText_QTBUG_45518(); void sideWidgets(); void shouldShowPlaceholderText_data(); @@ -4273,6 +4274,50 @@ void tst_QLineEdit::clearButton() QVERIFY(!clearButton->isEnabled()); } +void tst_QLineEdit::clearButtonVisibleAfterSettingText_QTBUG_45518() +{ +#ifndef QT_BUILD_INTERNAL + QSKIP("This test requires a developer build"); +#else + QLineEdit edit; + edit.setMinimumWidth(200); + centerOnScreen(&edit); + QLineEditIconButton *clearButton; + clearButton = edit.findChild<QLineEditIconButton *>(); + QVERIFY(!clearButton); + + edit.setText(QStringLiteral("some text")); + edit.show(); + QVERIFY(QTest::qWaitForWindowActive(&edit)); + + QVERIFY(!edit.isClearButtonEnabled()); + + clearButton = edit.findChild<QLineEditIconButton *>(); + QVERIFY(!clearButton); + + edit.setClearButtonEnabled(true); + QVERIFY(edit.isClearButtonEnabled()); + + clearButton = edit.findChild<QLineEditIconButton *>(); + QVERIFY(clearButton); + QVERIFY(clearButton->isVisible()); + + QTRY_VERIFY(clearButton->opacity() > 0); + QTRY_COMPARE(clearButton->cursor().shape(), Qt::ArrowCursor); + + QTest::mouseClick(clearButton, Qt::LeftButton, 0, clearButton->rect().center()); + QTRY_COMPARE(edit.text(), QString()); + + QTRY_COMPARE(clearButton->opacity(), qreal(0)); + QTRY_COMPARE(clearButton->cursor().shape(), clearButton->parentWidget()->cursor().shape()); + + edit.setClearButtonEnabled(false); + QVERIFY(!edit.isClearButtonEnabled()); + clearButton = edit.findChild<QLineEditIconButton *>(); + QVERIFY(!clearButton); +#endif // QT_BUILD_INTERNAL +} + void tst_QLineEdit::sideWidgets() { QWidget testWidget; |