QAbstractSpinBox: Clear 'cleared' flag on receiving a keypress
Prevent QAbstractSpinBoxPrivate::interpret() from bailing out in focus changes after text has been entered. Task-number: QTBUG-55249 Change-Id: I250b3c50f7db5de2e9356038df20f18ee059df11 Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
This commit is contained in:
parent
c0a513d55f
commit
1e85ca2e62
@ -1083,6 +1083,8 @@ void QAbstractSpinBox::keyPressEvent(QKeyEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
d->edit->event(event);
|
d->edit->event(event);
|
||||||
|
if (!d->edit->text().isEmpty())
|
||||||
|
d->cleared = false;
|
||||||
if (!isVisible())
|
if (!isVisible())
|
||||||
d->ignoreUpdateEdit = true;
|
d->ignoreUpdateEdit = true;
|
||||||
}
|
}
|
||||||
|
@ -143,6 +143,8 @@ private slots:
|
|||||||
|
|
||||||
void positiveSign();
|
void positiveSign();
|
||||||
|
|
||||||
|
void interpretOnLosingFocus();
|
||||||
|
|
||||||
void setGroupSeparatorShown_data();
|
void setGroupSeparatorShown_data();
|
||||||
void setGroupSeparatorShown();
|
void setGroupSeparatorShown();
|
||||||
|
|
||||||
@ -1150,6 +1152,33 @@ void tst_QSpinBox::positiveSign()
|
|||||||
QCOMPARE(spinBox.text(), QLatin1String("+20"));
|
QCOMPARE(spinBox.text(), QLatin1String("+20"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QSpinBox::interpretOnLosingFocus()
|
||||||
|
{
|
||||||
|
// QTBUG-55249: When typing an invalid value after QSpinBox::clear(),
|
||||||
|
// it should be fixed up on losing focus.
|
||||||
|
|
||||||
|
static const int minimumValue = 10;
|
||||||
|
static const int maximumValue = 20;
|
||||||
|
|
||||||
|
QWidget widget;
|
||||||
|
widget.setWindowTitle(QTest::currentTestFunction());
|
||||||
|
QVBoxLayout *layout = new QVBoxLayout(&widget);
|
||||||
|
QLineEdit *focusDummy = new QLineEdit("focusDummy", &widget);
|
||||||
|
layout->addWidget(focusDummy);
|
||||||
|
SpinBox *spinBox = new SpinBox(&widget);
|
||||||
|
spinBox->setRange(minimumValue, maximumValue);
|
||||||
|
spinBox->setValue(minimumValue);
|
||||||
|
layout->addWidget(spinBox);
|
||||||
|
spinBox->clear();
|
||||||
|
spinBox->setFocus();
|
||||||
|
widget.show();
|
||||||
|
QVERIFY(QTest::qWaitForWindowActive(&widget));
|
||||||
|
QTest::keyClick(spinBox, Qt::Key_1); // Too small
|
||||||
|
focusDummy->setFocus();
|
||||||
|
QCOMPARE(spinBox->value(), minimumValue);
|
||||||
|
QCOMPARE(spinBox->lineEdit()->text().toInt(), minimumValue);
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QSpinBox::setGroupSeparatorShown_data()
|
void tst_QSpinBox::setGroupSeparatorShown_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<QLocale::Language>("lang");
|
QTest::addColumn<QLocale::Language>("lang");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user