From 4326aef2d5bd1911af017f2cf384aee5d41e8a1a Mon Sep 17 00:00:00 2001 From: EdnY1 Date: Fri, 20 Sep 2024 22:13:34 -0400 Subject: [PATCH] Fixed horizontal scroll using trackpad gesture --- src/details/QCefViewPrivate.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/details/QCefViewPrivate.cpp b/src/details/QCefViewPrivate.cpp index 6448db66..9cda2b41 100644 --- a/src/details/QCefViewPrivate.cpp +++ b/src/details/QCefViewPrivate.cpp @@ -1036,18 +1036,22 @@ QCefViewPrivate::onViewWheelEvent(QWheelEvent* event) e.modifiers |= m & Qt::ControlModifier ? EVENTFLAG_CONTROL_DOWN : 0; e.modifiers |= m & Qt::ShiftModifier ? EVENTFLAG_SHIFT_DOWN : 0; e.modifiers |= m & Qt::AltModifier ? EVENTFLAG_ALT_DOWN : 0; - e.modifiers |= b & Qt::LeftButton ? EVENTFLAG_LEFT_MOUSE_BUTTON : 0; e.modifiers |= b & Qt::RightButton ? EVENTFLAG_RIGHT_MOUSE_BUTTON : 0; e.modifiers |= b & Qt::MiddleButton ? EVENTFLAG_MIDDLE_MOUSE_BUTTON : 0; e.x = p.x(); e.y = p.y(); - // angleDelta().y() provides the angle through which the common vertical mouse wheel was rotated since the previous - // event. angleDelta().x() provides the angle through which the horizontal mouse wheel was rotated, if the mouse has - // a horizontal wheel; otherwise it stays at zero. - pCefBrowser_->GetHost()->SendMouseWheelEvent( - e, m & Qt::ShiftModifier ? d.x() : 0, m & Qt::ShiftModifier ? d.y() : d.y()); + // Prevent diagonal scrolling: only allow scrolling in one direction at a time + if (d.x() != 0 && d.y() != 0) { + if (std::abs(d.x()) > std::abs(d.y())) { + d.setY(0); + } else { + d.setX(0); + } + } + + pCefBrowser_->GetHost()->SendMouseWheelEvent(e, d.x(), d.y()); } }