aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2018-03-23 10:44:05 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2018-03-23 12:14:43 +0000
commit2acf527d54049cfb17d1d2aaf4d77c97716e1dc6 (patch)
tree57c803313e941b13f8c58d30100425c6b43fd204
parent9529225c849ee8e697767350cbb08e5f2845681b (diff)
Combo|SpinBox: fix wheel event propagation
Sync the behavior with Qt Widgets. Don't propagate wheel events when reaching the end. The behavior was not nice, that a ScrollView underneath started suddenly moving whilst these input controls had input focus. Task-number: QTBUG-66044 Change-Id: I1b9c7f005652041cd82c77d4a1ca1a01d7d536e9 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/quicktemplates2/qquickcombobox.cpp2
-rw-r--r--src/quicktemplates2/qquickspinbox.cpp3
-rw-r--r--tests/auto/controls/data/tst_combobox.qml17
-rw-r--r--tests/auto/controls/data/tst_spinbox.qml17
4 files changed, 31 insertions, 8 deletions
diff --git a/src/quicktemplates2/qquickcombobox.cpp b/src/quicktemplates2/qquickcombobox.cpp
index 3639bf2f..d992c649 100644
--- a/src/quicktemplates2/qquickcombobox.cpp
+++ b/src/quicktemplates2/qquickcombobox.cpp
@@ -1639,12 +1639,10 @@ 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->decrementCurrentIndex();
else
d->incrementCurrentIndex();
- event->setAccepted(d->currentIndex != oldIndex);
}
}
#endif
diff --git a/src/quicktemplates2/qquickspinbox.cpp b/src/quicktemplates2/qquickspinbox.cpp
index 04bdec43..7412936c 100644
--- a/src/quicktemplates2/qquickspinbox.cpp
+++ b/src/quicktemplates2/qquickspinbox.cpp
@@ -955,8 +955,7 @@ void QQuickSpinBox::wheelEvent(QWheelEvent *event)
if (d->wheelEnabled) {
const QPointF angle = event->angleDelta();
const qreal delta = (qFuzzyIsNull(angle.y()) ? angle.x() : angle.y()) / QWheelEvent::DefaultDeltasPerStep;
- if (!d->stepBy(qRound(d->effectiveStepSize() * delta), true))
- event->ignore();
+ d->stepBy(qRound(d->effectiveStepSize() * delta), true);
}
}
#endif
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index 30d6a93c..22b36725 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -80,6 +80,11 @@ TestCase {
}
}
+ Component {
+ id: mouseArea
+ MouseArea { }
+ }
+
function init() {
// QTBUG-61225: Move the mouse away to avoid QQuickWindowPrivate::flushFrameSynchronousEvents()
// delivering interfering hover events based on the last mouse position from earlier tests. For
@@ -1042,24 +1047,34 @@ TestCase {
}
function test_wheel() {
- var control = createTemporaryObject(comboBox, testCase, {model: 2, wheelEnabled: true})
+ var ma = createTemporaryObject(mouseArea, testCase, {width: 100, height: 100})
+ verify(ma)
+
+ var control = comboBox.createObject(ma, {model: 2, wheelEnabled: true})
verify(control)
var delta = 120
+ var spy = signalSpy.createObject(ma, {target: ma, signalName: "wheel"})
+ verify(spy.valid)
+
mouseWheel(control, control.width / 2, control.height / 2, -delta, -delta)
compare(control.currentIndex, 1)
+ compare(spy.count, 0) // no propagation
// reached bounds -> no change
mouseWheel(control, control.width / 2, control.height / 2, -delta, -delta)
compare(control.currentIndex, 1)
+ compare(spy.count, 0) // no propagation
mouseWheel(control, control.width / 2, control.height / 2, delta, delta)
compare(control.currentIndex, 0)
+ compare(spy.count, 0) // no propagation
// reached bounds -> no change
mouseWheel(control, control.width / 2, control.height / 2, delta, delta)
compare(control.currentIndex, 0)
+ compare(spy.count, 0) // no propagation
}
function test_activation_data() {
diff --git a/tests/auto/controls/data/tst_spinbox.qml b/tests/auto/controls/data/tst_spinbox.qml
index 9568da1a..47c19f40 100644
--- a/tests/auto/controls/data/tst_spinbox.qml
+++ b/tests/auto/controls/data/tst_spinbox.qml
@@ -71,6 +71,11 @@ TestCase {
SpinBox { }
}
+ Component {
+ id: mouseArea
+ MouseArea { }
+ }
+
function test_defaults() {
var control = createTemporaryObject(spinBox, testCase)
verify(control)
@@ -401,7 +406,10 @@ TestCase {
}
function test_wheel(data) {
- var control = createTemporaryObject(spinBox, testCase, {wrap: data.wrap, from: data.from, to: data.to, value: data.value, stepSize: data.stepSize, wheelEnabled: true})
+ var ma = createTemporaryObject(mouseArea, testCase, {width: 100, height: 100})
+ verify(ma)
+
+ var control = spinBox.createObject(ma, {wrap: data.wrap, from: data.from, to: data.to, value: data.value, stepSize: data.stepSize, wheelEnabled: true})
verify(control)
var valueModifiedCount = 0
@@ -410,13 +418,16 @@ TestCase {
var delta = 120
+ var spy = signalSpy.createObject(ma, {target: ma, signalName: "wheel"})
+ verify(spy.valid)
+
for (var u = 0; u < data.upSteps.length; ++u) {
var wasUpEnabled = control.wrap || control.value < control.to
mouseWheel(control, control.width / 2, control.height / 2, delta, delta)
if (wasUpEnabled)
++valueModifiedCount
compare(valueModifiedSpy.count, valueModifiedCount)
-
+ compare(spy.count, 0) // no propagation
compare(control.value, data.upSteps[u])
}
@@ -426,7 +437,7 @@ TestCase {
if (wasDownEnabled)
++valueModifiedCount
compare(valueModifiedSpy.count, valueModifiedCount)
-
+ compare(spy.count, 0) // no propagation
compare(control.value, data.downSteps[d])
}
}