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 7d29807296 changed it so that the
vertical mouse wheel could no longer scroll a horizontal scrollbar.
The behavior is now restored as it was in
59cc316620.

Task-number: QTBUG-81007
Change-Id: Ieacdce539d5311499a86af645bbe0d5098e16be6
Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
bb10
Christian Ehrlicher 2019-12-29 16:27:29 +01:00 committed by Shawn Rutledge
parent 7d7ba311e0
commit 9dcbf2cf5c
1 changed files with 8 additions and 2 deletions

View File

@ -497,14 +497,20 @@ bool QScrollBar::event(QEvent *event)
void QScrollBar::wheelEvent(QWheelEvent *event)
{
event->ignore();
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();
Q_D(QScrollBar);
if (d->scrollByDelta(orientation(), event->modifiers(), delta))
if (d->scrollByDelta(horizontal ? Qt::Horizontal : Qt::Vertical, event->modifiers(), delta))
event->accept();
if (event->phase() == Qt::ScrollBegin)