From 3a536482094e54a567fa4438c2c5a4c6405cadd2 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 16 Oct 2023 21:29:43 +0200 Subject: [PATCH] GuiUtils: Make wheel blocker transitive Instead of consuming the wheel event, pass it to the target widget's parent. This should allow for further scrolling the possible parent scroll area. Modify the focus policy only in case of WheelFocus. Change-Id: I00c628a9e3d7608222b0700e71469c6cef6dea88 Reviewed-by: Eike Ziller --- src/libs/utils/guiutils.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/libs/utils/guiutils.cpp b/src/libs/utils/guiutils.cpp index bfafff677f7..7789f83993b 100644 --- a/src/libs/utils/guiutils.cpp +++ b/src/libs/utils/guiutils.cpp @@ -14,11 +14,15 @@ class WheelEventFilter : public QObject { public: bool eventFilter(QObject *watched, QEvent *event) override { - auto widget = qobject_cast(watched); - return event->type() == QEvent::Wheel - && widget - && widget->focusPolicy() != Qt::WheelFocus - && !widget->hasFocus(); + if (event->type() == QEvent::Wheel) { + QWidget *widget = qobject_cast(watched); + if (widget && widget->focusPolicy() != Qt::WheelFocus && !widget->hasFocus()) { + QObject *parent = widget->parentWidget(); + if (parent) + return parent->event(event); + } + } + return QObject::eventFilter(watched, event); } }; @@ -28,7 +32,8 @@ void QTCREATOR_UTILS_EXPORT attachWheelBlocker(QWidget *widget) { static Internal::WheelEventFilter instance; widget->installEventFilter(&instance); - widget->setFocusPolicy(Qt::StrongFocus); + if (widget->focusPolicy() == Qt::WheelFocus) + widget->setFocusPolicy(Qt::StrongFocus); } } // namespace Utils