path: root/src
diff options
authorChristian Ehrlicher <>2019-12-29 16:27:29 +0100
committerShawn Rutledge <>2020-01-13 16:40:34 +0100
commit9dcbf2cf5cbdfe35637ff323fd44729badaae811 (patch)
tree031c1910d6b25b3f9ba38181a6ff0fb3847a0933 /src
parent7d7ba311e01f915c32df53d6a6c4ca982efc24e1 (diff)
QScrollBar: allow scrolling any scrollbar with any mouse wheel
The most common mouse wheel movement corresponds to angleDelta().y(). We have previously allowed the user to use either wheel to scroll either a horizontal or a vertical scrollbar when the mouse is hovering over it; but 7d29807296cb7ccc7f3459e106d74f93a321c493 changed it so that the vertical mouse wheel could no longer scroll a horizontal scrollbar. The behavior is now restored as it was in 59cc316620a2169d48e00822c97a96bd03079eed. Task-number: QTBUG-81007 Change-Id: Ieacdce539d5311499a86af645bbe0d5098e16be6 Reviewed-by: Christian Ehrlicher <> Reviewed-by: Shawn Rutledge <>
Diffstat (limited to 'src')
1 files changed, 8 insertions, 2 deletions
diff --git a/src/widgets/widgets/qscrollbar.cpp b/src/widgets/widgets/qscrollbar.cpp
index 08d771a27a..4606f57fb8 100644
--- a/src/widgets/widgets/qscrollbar.cpp
+++ b/src/widgets/widgets/qscrollbar.cpp
@@ -497,14 +497,20 @@ bool QScrollBar::event(QEvent *event)
void QScrollBar::wheelEvent(QWheelEvent *event)
+ bool horizontal = qAbs(event->angleDelta().x()) > qAbs(event->angleDelta().y());
+ // The vertical wheel can be used to scroll a horizontal scrollbar, but only if
+ // there is no simultaneous horizontal wheel movement. This is to avoid chaotic
+ // scrolling on touchpads.
+ if (!horizontal && event->angleDelta().x() != 0 && orientation() == Qt::Horizontal)
+ return;
// scrollbar is a special case - in vertical mode it reaches minimum
// value in the upper position, however QSlider's minimum value is on
// the bottom. So we need to invert the value, but since the scrollbar is
// inverted by default, we need to invert the delta value only for the
// horizontal orientation.
- int delta = (orientation() == Qt::Horizontal ? -event->angleDelta().x() : event->angleDelta().y());
+ int delta = horizontal ? -event->angleDelta().x() : event->angleDelta().y();
- if (d->scrollByDelta(orientation(), event->modifiers(), delta))
+ if (d->scrollByDelta(horizontal ? Qt::Horizontal : Qt::Vertical, event->modifiers(), delta))
if (event->phase() == Qt::ScrollBegin)