From 92eff047d65939aa27ed6eeeeecfcf158ed9bafb Mon Sep 17 00:00:00 2001 From: Oliver Eftevaag Date: Thu, 1 Aug 2024 15:03:11 +0200 Subject: [PATCH] Slider: use axis with the largest delta, when sliding via wheelEvent The slider naively assumed that all wheelEvents would have either angleDelta().x(), or angleDelta().y() set to 0, when in reality those numbers can be any floating point value. Choosing the largest of the two deltas, is a more robust solution. Pick-to: 6.8 Change-Id: I1fb75eb5121c99c9b354e53732ec6981f477e283 Reviewed-by: Paul Olav Tvete --- src/quicktemplates/qquickslider.cpp | 2 +- tests/auto/quickcontrols/controls/data/tst_slider.qml | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/quicktemplates/qquickslider.cpp b/src/quicktemplates/qquickslider.cpp index 063090cc70..0a95542be7 100644 --- a/src/quicktemplates/qquickslider.cpp +++ b/src/quicktemplates/qquickslider.cpp @@ -837,7 +837,7 @@ void QQuickSlider::wheelEvent(QWheelEvent *event) if (d->wheelEnabled) { const qreal oldValue = d->value; const QPointF angle = event->angleDelta(); - const qreal delta = (qFuzzyIsNull(angle.y()) ? angle.x() : (event->inverted() ? -angle.y() : angle.y())) / int(QWheelEvent::DefaultDeltasPerStep); + const qreal delta = (qAbs(angle.y()) < qAbs(angle.x()) ? angle.x() : (event->inverted() ? -angle.y() : angle.y())) / int(QWheelEvent::DefaultDeltasPerStep); const qreal step = qFuzzyIsNull(d->stepSize) ? 0.1 : d->stepSize; setValue(oldValue + step * delta); const bool wasMoved = !qFuzzyCompare(d->value, oldValue); diff --git a/tests/auto/quickcontrols/controls/data/tst_slider.qml b/tests/auto/quickcontrols/controls/data/tst_slider.qml index 991d513122..8b76d9c515 100644 --- a/tests/auto/quickcontrols/controls/data/tst_slider.qml +++ b/tests/auto/quickcontrols/controls/data/tst_slider.qml @@ -692,7 +692,9 @@ TestCase { function test_wheel_data() { return [ { tag: "horizontal", orientation: Qt.Horizontal, dx: 120, dy: 0 }, - { tag: "vertical", orientation: Qt.Vertical, dx: 0, dy: 120 } + { tag: "vertical", orientation: Qt.Vertical, dx: 0, dy: 120 }, + { tag: "mostlyHorizontal", orientation: Qt.Horizontal, dx: 120, dy: 1 }, + { tag: "mostlyVertical", orientation: Qt.Vertical, dx: 1, dy: 120 }, ] }