Ensure textEdited() is emitted if the input is changed by a validator
[ChangeLog][QtWidgets][QLineEdit] The textEdited() signal is now emitted even if the QValidator has changed the user input. Task-number: QTBUG-44046 Change-Id: Ife287269c7dcbb644cb03a291bf96f7db384ed56 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
3d31afe1e4
commit
357822818d
@ -711,7 +711,7 @@ bool QWidgetLineControl::finishChange(int validateFromState, bool update, bool e
|
||||
m_validInput = (m_validator->validate(textCopy, cursorCopy) != QValidator::Invalid);
|
||||
if (m_validInput) {
|
||||
if (m_text != textCopy) {
|
||||
internalSetText(textCopy, cursorCopy, false);
|
||||
internalSetText(textCopy, cursorCopy, edited);
|
||||
return true;
|
||||
}
|
||||
m_cursor = cursorCopy;
|
||||
|
@ -2268,6 +2268,16 @@ void tst_QLineEdit::deleteSelectedText()
|
||||
|
||||
}
|
||||
|
||||
class ToUpperValidator : public QValidator
|
||||
{
|
||||
public:
|
||||
ToUpperValidator() {}
|
||||
State validate(QString &input, int &) const override
|
||||
{
|
||||
input = input.toUpper();
|
||||
return QValidator::Acceptable;
|
||||
}
|
||||
};
|
||||
|
||||
void tst_QLineEdit::textChangedAndTextEdited()
|
||||
{
|
||||
@ -2309,6 +2319,23 @@ void tst_QLineEdit::textChangedAndTextEdited()
|
||||
QCOMPARE(edited_count, 0);
|
||||
QVERIFY(changed_string.isEmpty());
|
||||
QVERIFY(!changed_string.isNull());
|
||||
|
||||
changed_count = 0;
|
||||
edited_count = 0;
|
||||
changed_string.clear();
|
||||
|
||||
QScopedPointer<ToUpperValidator> validator(new ToUpperValidator());
|
||||
testWidget->setValidator(validator.data());
|
||||
testWidget->setText("foo");
|
||||
QCOMPARE(changed_count, 1);
|
||||
QCOMPARE(edited_count, 0);
|
||||
QCOMPARE(changed_string, QLatin1String("FOO"));
|
||||
testWidget->setCursorPosition(sizeof("foo"));
|
||||
QTest::keyClick(testWidget, 'b');
|
||||
QCOMPARE(changed_count, 2);
|
||||
QCOMPARE(edited_count, 1);
|
||||
QCOMPARE(changed_string, QLatin1String("FOOB"));
|
||||
testWidget->setValidator(nullptr);
|
||||
}
|
||||
|
||||
void tst_QLineEdit::onTextChanged(const QString &text)
|
||||
|
Loading…
Reference in New Issue
Block a user