From dfb4af1fd34a163495790a7896acafa56b86a8f1 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 8 Sep 2014 16:22:29 +0200 Subject: Fix spin box with fine grained wheel events Only step the value in the spin box when we have accumulated one wheel tick worth of wheel delta. Also fixes the obsolete contructors of QWheelEvent so they set the non obsolete properties. Change-Id: Ic6ea4b37afa8eec85a6ca7bdc0d919bf8fb02608 Reviewed-by: Shawn Rutledge --- .../auto/widgets/widgets/qspinbox/tst_qspinbox.cpp | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests/auto/widgets/widgets/qspinbox') diff --git a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp index 350ae23d8a..ac76c44b9b 100644 --- a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp +++ b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp @@ -82,6 +82,12 @@ public: { return QSpinBox::valueFromText(text); } +#ifndef QT_NO_WHEELEVENT + void wheelEvent(QWheelEvent *event) + { + QSpinBox::wheelEvent(event); + } +#endif QLineEdit *lineEdit() const { return QSpinBox::lineEdit(); } }; @@ -148,6 +154,8 @@ private slots: void setGroupSeparatorShown_data(); void setGroupSeparatorShown(); + void wheelEvents(); + public slots: void valueChangedHelper(const QString &); void valueChangedHelper(int); @@ -1190,5 +1198,29 @@ void tst_QSpinBox::setGroupSeparatorShown() QCOMPARE(spinBox.value()+1000, 33000); } +void tst_QSpinBox::wheelEvents() +{ +#ifndef QT_NO_WHEELEVENT + SpinBox spinBox; + spinBox.setRange(-20, 20); + spinBox.setValue(0); + + QWheelEvent wheelUp(QPointF(), QPointF(), QPoint(), QPoint(0, 120), 120, Qt::Vertical, Qt::NoButton, Qt::NoModifier); + spinBox.wheelEvent(&wheelUp); + QCOMPARE(spinBox.value(), 1); + + QWheelEvent wheelDown(QPointF(), QPointF(), QPoint(), QPoint(0, -120), -120, Qt::Vertical, Qt::NoButton, Qt::NoModifier); + spinBox.wheelEvent(&wheelDown); + spinBox.wheelEvent(&wheelDown); + QCOMPARE(spinBox.value(), -1); + + QWheelEvent wheelHalfUp(QPointF(), QPointF(), QPoint(), QPoint(0, 60), 60, Qt::Vertical, Qt::NoButton, Qt::NoModifier); + spinBox.wheelEvent(&wheelHalfUp); + QCOMPARE(spinBox.value(), -1); + spinBox.wheelEvent(&wheelHalfUp); + QCOMPARE(spinBox.value(), 0); +#endif +} + QTEST_MAIN(tst_QSpinBox) #include "tst_qspinbox.moc" -- cgit v1.2.3