diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2013-12-02 14:42:58 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-12-11 19:21:27 +0100 |
commit | a2666d33919807ba6170f55f8e74a71ef8392a4d (patch) | |
tree | 24edae588b582771599963fc9b651d285a42a8dd /tests/auto/widgets/widgets/qlineedit | |
parent | fc5e948ea8b2f9b54c3468d32f7e04f92d247567 (diff) |
QLineEdit: hide placeholder text when h-centered & focused
[ChangeLog][QtWidgets][QLineEdit] A blinking cursor in the middle
over horizontally centered placeholder text looks bad. Thus,
horizontally centered content is now considered as an exception
and the placeholder text is hidden when the line edit is focused.
Task-number: QTBUG-31669
Change-Id: I17aa1e6656673f81545a8437f90814b188ad484a
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'tests/auto/widgets/widgets/qlineedit')
-rw-r--r-- | tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index a9f5cb686c..d6d48a1e8d 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -53,7 +53,7 @@ #include "qstandarditemmodel.h" #include <qpa/qplatformtheme.h> #include "qstylehints.h" -#include <private/qguiapplication_p.h> +#include <private/qapplication_p.h> #include "qclipboard.h" #ifdef Q_OS_MAC @@ -300,6 +300,9 @@ private slots: void clearButton(); void sideWidgets(); + void shouldShowPlaceholderText_data(); + void shouldShowPlaceholderText(); + protected slots: void editingFinished(); @@ -4136,5 +4139,59 @@ void tst_QLineEdit::sideWidgets() lineEdit->addAction(iconAction); } +Q_DECLARE_METATYPE(Qt::AlignmentFlag) +void tst_QLineEdit::shouldShowPlaceholderText_data() +{ + QTest::addColumn<QString>("text"); + QTest::addColumn<bool>("hasFocus"); + QTest::addColumn<Qt::AlignmentFlag>("alignment"); + QTest::addColumn<bool>("shouldShowPlaceholderText"); + + QTest::newRow("empty, non-focused, left") << QString() << false << Qt::AlignLeft << true; + QTest::newRow("empty, focused, left") << QString() << true << Qt::AlignLeft << true; + QTest::newRow("non-empty, non-focused, left") << QStringLiteral("Qt") << false << Qt::AlignLeft << false; + QTest::newRow("non-empty, focused, left") << QStringLiteral("Qt") << true << Qt::AlignLeft << false; + + QTest::newRow("empty, non-focused, center") << QString() << false << Qt::AlignHCenter << true; + QTest::newRow("empty, focused, center") << QString() << true << Qt::AlignHCenter << false; + QTest::newRow("non-empty, non-focused, center") << QStringLiteral("Qt") << false << Qt::AlignHCenter << false; + QTest::newRow("non-empty, focused, center") << QStringLiteral("Qt") << true << Qt::AlignHCenter << false; + + QTest::newRow("empty, non-focused, right") << QString() << false << Qt::AlignRight << true; + QTest::newRow("empty, focused, right") << QString() << true << Qt::AlignRight << true; + QTest::newRow("non-empty, non-focused, right") << QStringLiteral("Qt") << false << Qt::AlignRight << false; + QTest::newRow("non-empty, focused, right") << QStringLiteral("Qt") << true << Qt::AlignRight << false; +} + +void tst_QLineEdit::shouldShowPlaceholderText() +{ +#ifndef QT_BUILD_INTERNAL + QSKIP("This test requires a developer build."); +#else + QFETCH(QString, text); + QFETCH(bool, hasFocus); + QFETCH(Qt::AlignmentFlag, alignment); + QFETCH(bool, shouldShowPlaceholderText); + + QLineEdit lineEdit; + + // avoid "Test input context to commit without focused object" warnings + lineEdit.setAttribute(Qt::WA_InputMethodEnabled, false); + + if (hasFocus) { + lineEdit.show(); + QApplicationPrivate::setFocusWidget(&lineEdit, Qt::NoFocusReason); + } + QCOMPARE(lineEdit.hasFocus(), hasFocus); + + lineEdit.setText(text); + lineEdit.setAlignment(alignment); + + QLineEditPrivate *priv = QLineEditPrivate::get(&lineEdit); + QCOMPARE(priv->shouldShowPlaceholderText(), shouldShowPlaceholderText); +#endif + +} + QTEST_MAIN(tst_QLineEdit) #include "tst_qlineedit.moc" |