aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2016-03-03 14:19:45 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2016-03-04 10:49:25 +0000
commit11b431ca82d2e0234918b910f9361ff9583a2f8a (patch)
treef87cf0e334699b7475585694b497255d07d6b933
parentdc78d00db6128ee53953b0cf01dcbfe236a849c3 (diff)
QQuickComboBox: handle wheel events to respect wheelEnabled
Change-Id: I372c56d5a8fdda575d1e9a3d5fe4281c2c4f8c3c Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
-rw-r--r--src/templates/qquickcombobox.cpp14
-rw-r--r--src/templates/qquickcombobox_p.h1
-rw-r--r--tests/auto/controls/data/tst_combobox.qml23
3 files changed, 38 insertions, 0 deletions
diff --git a/src/templates/qquickcombobox.cpp b/src/templates/qquickcombobox.cpp
index c4e38ec2..31703536 100644
--- a/src/templates/qquickcombobox.cpp
+++ b/src/templates/qquickcombobox.cpp
@@ -806,6 +806,20 @@ void QQuickComboBox::mouseUngrabEvent()
setPressed(false);
}
+void QQuickComboBox::wheelEvent(QWheelEvent *event)
+{
+ Q_D(QQuickComboBox);
+ QQuickControl::wheelEvent(event);
+ if (d->wheelEnabled && !d->isPopupVisible()) {
+ const int oldIndex = d->currentIndex;
+ if (event->angleDelta().y() > 0)
+ d->decrease();
+ else
+ d->increase();
+ event->setAccepted(d->currentIndex != oldIndex);
+ }
+}
+
void QQuickComboBox::componentComplete()
{
Q_D(QQuickComboBox);
diff --git a/src/templates/qquickcombobox_p.h b/src/templates/qquickcombobox_p.h
index 431dccb0..42fc962b 100644
--- a/src/templates/qquickcombobox_p.h
+++ b/src/templates/qquickcombobox_p.h
@@ -131,6 +131,7 @@ protected:
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseUngrabEvent() override;
+ void wheelEvent(QWheelEvent *event) override;
void componentComplete() override;
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index df135b1a..6e593967 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -763,4 +763,27 @@ TestCase {
control.destroy()
}
+
+ function test_wheel(data) {
+ var control = comboBox.createObject(applicationWindow.contentItem, {model: 2, wheelEnabled: true})
+ verify(control)
+
+ var delta = 120
+
+ mouseWheel(control, control.width / 2, control.height / 2, -delta, -delta)
+ compare(control.currentIndex, 1)
+
+ // reached bounds -> no change
+ mouseWheel(control, control.width / 2, control.height / 2, -delta, -delta)
+ compare(control.currentIndex, 1)
+
+ mouseWheel(control, control.width / 2, control.height / 2, delta, delta)
+ compare(control.currentIndex, 0)
+
+ // reached bounds -> no change
+ mouseWheel(control, control.width / 2, control.height / 2, delta, delta)
+ compare(control.currentIndex, 0)
+
+ control.destroy()
+ }
}