diff options
author | Andy Shaw <andy.shaw@qt.io> | 2018-05-30 20:58:24 +0200 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2018-06-01 21:34:03 +0000 |
commit | c901cdadc0a6ec65eddfe4f181274e56567f9973 (patch) | |
tree | 0cd722d395efc2b96a394ac862f1cda6ff61a9c3 /tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp | |
parent | e3e0a6d6d6c50dc21439f24728ee3614c5825d36 (diff) |
QLineEdit: Add an inputRejected() signal for when a key is not allowed
[ChangeLog][QtWidgets][QLineEdit] Added inputRejected() signal for when
a key press is not accepted by the QLineEdit. For instance, when an
invalid key is pressed for a validator set.
Task-number: QTBUG-57448
Change-Id: I39182a78b07b37c6da01905b8da4c57930e3454b
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp')
-rw-r--r-- | tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index 7eb739611a..6e472bff02 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -304,7 +304,7 @@ private slots: void QTBUG59957_clearButtonLeftmostAction(); void QTBUG_60319_setInputMaskCheckImSurroundingText(); void testQuickSelectionWithMouse(); - + void inputRejected(); protected slots: void editingFinished(); @@ -4820,5 +4820,44 @@ void tst_QLineEdit::testQuickSelectionWithMouse() QVERIFY(lineEdit.selectedText().endsWith(suffix)); } +void tst_QLineEdit::inputRejected() +{ + QLineEdit *testWidget = ensureTestWidget(); + QSignalSpy spyInputRejected(testWidget, SIGNAL(inputRejected())); + + QTest::keyClicks(testWidget, "abcde"); + QCOMPARE(spyInputRejected.count(), 0); + testWidget->setText("fghij"); + QCOMPARE(spyInputRejected.count(), 0); + testWidget->insert("k"); + QCOMPARE(spyInputRejected.count(), 0); + + testWidget->clear(); + testWidget->setMaxLength(5); + QTest::keyClicks(testWidget, "abcde"); + QCOMPARE(spyInputRejected.count(), 0); + QTest::keyClicks(testWidget, "fgh"); + QCOMPARE(spyInputRejected.count(), 3); + + testWidget->setMaxLength(INT_MAX); + testWidget->clear(); + spyInputRejected.clear(); + QIntValidator intValidator(1, 100); + testWidget->setValidator(&intValidator); + QTest::keyClicks(testWidget, "11"); + QCOMPARE(spyInputRejected.count(), 0); + QTest::keyClicks(testWidget, "a#"); + QCOMPARE(spyInputRejected.count(), 2); + + testWidget->clear(); + testWidget->setValidator(0); + spyInputRejected.clear(); + testWidget->setInputMask("999.999.999.999;_"); + QTest::keyClicks(testWidget, "11"); + QCOMPARE(spyInputRejected.count(), 0); + QTest::keyClicks(testWidget, "a#"); + QCOMPARE(spyInputRejected.count(), 2); +} + QTEST_MAIN(tst_QLineEdit) #include "tst_qlineedit.moc" |