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 <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2023-10-16 21:29:43 +02:00
parent e928c19d27
commit 3a53648209

View File

@@ -14,11 +14,15 @@ class WheelEventFilter : public QObject
{
public:
bool eventFilter(QObject *watched, QEvent *event) override {
auto widget = qobject_cast<QWidget *>(watched);
return event->type() == QEvent::Wheel
&& widget
&& widget->focusPolicy() != Qt::WheelFocus
&& !widget->hasFocus();
if (event->type() == QEvent::Wheel) {
QWidget *widget = qobject_cast<QWidget *>(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