diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-12-10 11:27:51 +0100 |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-12-10 11:29:28 +0100 |
commit | bb0ab1d8cf57dd4a7b69c8478c2a40c1cd1782e9 (patch) | |
tree | 6791642658e71828ce796dc4fc11c06a83e5462b | |
parent | ba9ea2b97bdd2329cb479bb7a6aef1bc7cee82d1 (diff) | |
download | qt4-tools-bb0ab1d8cf57dd4a7b69c8478c2a40c1cd1782e9.tar.gz |
Fix spinbox input when seecting the prefix
If you were selcting the prefix and entering a digit the cursor position
would not be updated correctly
Task-number: QTBUG-6670
Reviewed-by: ogoffart
-rw-r--r-- | src/gui/widgets/qabstractspinbox.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qdoublespinbox/tst_qdoublespinbox.cpp | 12 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/gui/widgets/qabstractspinbox.cpp b/src/gui/widgets/qabstractspinbox.cpp index a18af4f0c6..c015589735 100644 --- a/src/gui/widgets/qabstractspinbox.cpp +++ b/src/gui/widgets/qabstractspinbox.cpp @@ -1856,8 +1856,10 @@ QValidator::State QSpinBoxValidator::validate(QString &input, int &pos) const if (dptr->specialValueText.size() > 0 && input == dptr->specialValueText) return QValidator::Acceptable; - if (!dptr->prefix.isEmpty() && !input.startsWith(dptr->prefix)) + if (!dptr->prefix.isEmpty() && !input.startsWith(dptr->prefix)) { input.prepend(dptr->prefix); + pos += dptr->prefix.length(); + } if (!dptr->suffix.isEmpty() && !input.endsWith(dptr->suffix)) input.append(dptr->suffix); diff --git a/tests/auto/qdoublespinbox/tst_qdoublespinbox.cpp b/tests/auto/qdoublespinbox/tst_qdoublespinbox.cpp index 7f031530af..a3f0915953 100644 --- a/tests/auto/qdoublespinbox/tst_qdoublespinbox.cpp +++ b/tests/auto/qdoublespinbox/tst_qdoublespinbox.cpp @@ -148,6 +148,7 @@ private slots: void task255471_decimalsValidation(); void taskQTBUG_5008_textFromValueAndValidate(); + void taskQTBUG_6670_selectAllWithPrefix(); public slots: void valueChangedHelper(const QString &); @@ -1084,5 +1085,16 @@ void tst_QDoubleSpinBox::taskQTBUG_5008_textFromValueAndValidate() QCOMPARE(spinbox.text(), spinbox.locale().toString(spinbox.value())); } +void tst_QDoubleSpinBox::taskQTBUG_6670_selectAllWithPrefix() +{ + DoubleSpinBox spin; + spin.setPrefix("$ "); + spin.lineEdit()->selectAll(); + QTest::keyClick(spin.lineEdit(), Qt::Key_1); + QCOMPARE(spin.value(), 1.); + QTest::keyClick(spin.lineEdit(), Qt::Key_2); + QCOMPARE(spin.value(), 12.); +} + QTEST_MAIN(tst_QDoubleSpinBox) #include "tst_qdoublespinbox.moc" |