QSpinBox: allow positive values to be entered with the '+' prefix.
The code was there to do it, but it was using minimumValue instead of maximumValue to test if the '+' should be allowed. Task-number: QTBUG-20691 [ChangeLog][QtWidgets][QSpinBox] Entering positive values with the '+' prefix is now allowed. Change-Id: Iff62d073e350dc9a33b7e06e4b492048c74437c4 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
eb7b140d6d
commit
b9c8073230
@ -1040,7 +1040,7 @@ QVariant QSpinBoxPrivate::validateAndInterpret(QString &input, int &pos,
|
||||
|
||||
if (max != min && (copy.isEmpty()
|
||||
|| (min < 0 && copy == QLatin1String("-"))
|
||||
|| (min >= 0 && copy == QLatin1String("+")))) {
|
||||
|| (max >= 0 && copy == QLatin1String("+")))) {
|
||||
state = QValidator::Intermediate;
|
||||
QSBDEBUG() << __FILE__ << __LINE__<< "num is set to" << num;
|
||||
} else if (copy.startsWith(QLatin1Char('-')) && min >= 0) {
|
||||
|
@ -142,6 +142,8 @@ private slots:
|
||||
|
||||
void taskQTBUG_5008_textFromValueAndValidate();
|
||||
void lineEditReturnPressed();
|
||||
|
||||
void positiveSign();
|
||||
public slots:
|
||||
void valueChangedHelper(const QString &);
|
||||
void valueChangedHelper(int);
|
||||
@ -1111,5 +1113,20 @@ void tst_QSpinBox::lineEditReturnPressed()
|
||||
QCOMPARE(spyCurrentChanged.count(), 1);
|
||||
}
|
||||
|
||||
void tst_QSpinBox::positiveSign()
|
||||
{
|
||||
QSpinBox spinBox;
|
||||
spinBox.setRange(-20, 20);
|
||||
spinBox.setValue(-20);
|
||||
spinBox.show();
|
||||
QVERIFY(QTest::qWaitForWindowActive(&spinBox));
|
||||
|
||||
QTest::keyClick(&spinBox, Qt::Key_End, Qt::ShiftModifier);
|
||||
QTest::keyClick(&spinBox, Qt::Key_Plus, Qt::ShiftModifier);
|
||||
QTest::keyClick(&spinBox, Qt::Key_2);
|
||||
QTest::keyClick(&spinBox, Qt::Key_0);
|
||||
QCOMPARE(spinBox.text(), QLatin1String("+20"));
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QSpinBox)
|
||||
#include "tst_qspinbox.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user