diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-07-06 13:15:25 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2021-07-12 11:25:24 +0200 |
commit | 2b0c12a66a8e8efea37471c59f1c072beb77c9cd (patch) | |
tree | 2d544e8bcf9d2d433ed901adcf17f144c72736a4 | |
parent | 187c24b670fe6d19fb9780cac0945f2eba2d45c0 (diff) |
QQuickOverlay: Handle hover events
With recent changes to hover handling logic, hover events would have
been sent to the "main window", even if a popup were modal. As this is
unwanted (a modally blocked button should not auto-raise when hovered),
we now prevent delivery of those events in QQuickOverlay and
overlayEvent.
The logic is the same as for mouse and touch events: If we get a
matching event, we ask the popup to handle it. The popup then uses the
existing blockInput logic to decide whether the event should be blocked
or forwarded.
Change-Id: I2194fd8e832592efd5b7b9697412bdaeaea74b83
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
(cherry picked from commit 48da34f3d797f58b3eda9ed0a98aa1776d75d946)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/quicktemplates2/qquickoverlay.cpp | 20 | ||||
-rw-r--r-- | src/quicktemplates2/qquickoverlay_p_p.h | 1 | ||||
-rw-r--r-- | src/quicktemplates2/qquickpopup.cpp | 17 | ||||
-rw-r--r-- | src/quicktemplates2/qquickpopup_p_p.h | 1 |
4 files changed, 39 insertions, 0 deletions
diff --git a/src/quicktemplates2/qquickoverlay.cpp b/src/quicktemplates2/qquickoverlay.cpp index 982834d820..6689d93c98 100644 --- a/src/quicktemplates2/qquickoverlay.cpp +++ b/src/quicktemplates2/qquickoverlay.cpp @@ -207,6 +207,22 @@ bool QQuickOverlayPrivate::handleMouseEvent(QQuickItem *source, QMouseEvent *eve return false; } +bool QQuickOverlayPrivate::handleHoverEvent(QQuickItem *source, QHoverEvent *event, QQuickPopup *target) +{ + switch (event->type()) { + case QEvent::HoverEnter: + case QEvent::HoverMove: + case QEvent::HoverLeave: + if (target) + return target->overlayEvent(source, event); + return false; + default: + Q_UNREACHABLE(); // function must only be called on hover events + break; + } + return false; +} + #if QT_CONFIG(quicktemplates2_multitouch) bool QQuickOverlayPrivate::handleTouchEvent(QQuickItem *source, QTouchEvent *event, QQuickPopup *target) { @@ -474,6 +490,10 @@ bool QQuickOverlay::childMouseEventFilter(QQuickItem *item, QEvent *event) case QEvent::TouchEnd: return d->handleTouchEvent(item, static_cast<QTouchEvent *>(event), popup); #endif + case QEvent::HoverEnter: + case QEvent::HoverMove: + case QEvent::HoverLeave: + return d->handleHoverEvent(item, static_cast<QHoverEvent *>(event), popup); case QEvent::MouseButtonPress: case QEvent::MouseMove: diff --git a/src/quicktemplates2/qquickoverlay_p_p.h b/src/quicktemplates2/qquickoverlay_p_p.h index ef3d9ee23e..fbb2f86c73 100644 --- a/src/quicktemplates2/qquickoverlay_p_p.h +++ b/src/quicktemplates2/qquickoverlay_p_p.h @@ -74,6 +74,7 @@ public: bool handleRelease(QQuickItem *source, QEvent *event, QQuickPopup *target); bool handleMouseEvent(QQuickItem *source, QMouseEvent *event, QQuickPopup *target = nullptr); + bool handleHoverEvent(QQuickItem *source, QHoverEvent *event, QQuickPopup *target = nullptr); #if QT_CONFIG(quicktemplates2_multitouch) bool handleTouchEvent(QQuickItem *source, QTouchEvent *event, QQuickPopup *target = nullptr); #endif diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp index ebb85c1211..cb78d634d5 100644 --- a/src/quicktemplates2/qquickpopup.cpp +++ b/src/quicktemplates2/qquickpopup.cpp @@ -412,6 +412,19 @@ bool QQuickPopupPrivate::handleMouseEvent(QQuickItem *item, QMouseEvent *event) } } +bool QQuickPopupPrivate::handleHoverEvent(QQuickItem *item, QHoverEvent *event) +{ + switch (event->type()) { + case QEvent::HoverEnter: + case QEvent::HoverMove: + case QEvent::HoverLeave: + return blockInput(item, event->scenePosition()); + default: + Q_UNREACHABLE(); + return false; + } +} + #if QT_CONFIG(quicktemplates2_multitouch) bool QQuickPopupPrivate::handleTouchEvent(QQuickItem *item, QTouchEvent *event) { @@ -2558,6 +2571,10 @@ bool QQuickPopup::overlayEvent(QQuickItem *item, QEvent *event) case QEvent::TouchEnd: return d->handleTouchEvent(item, static_cast<QTouchEvent *>(event)); #endif + case QEvent::HoverEnter: + case QEvent::HoverMove: + case QEvent::HoverLeave: + return d->handleHoverEvent(item, static_cast<QHoverEvent *>(event)); case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: diff --git a/src/quicktemplates2/qquickpopup_p_p.h b/src/quicktemplates2/qquickpopup_p_p.h index 5ce1d2916f..0a00c2aad0 100644 --- a/src/quicktemplates2/qquickpopup_p_p.h +++ b/src/quicktemplates2/qquickpopup_p_p.h @@ -120,6 +120,7 @@ public: virtual void handleUngrab(); bool handleMouseEvent(QQuickItem *item, QMouseEvent *event); + bool handleHoverEvent(QQuickItem *item, QHoverEvent *event); #if QT_CONFIG(quicktemplates2_multitouch) bool handleTouchEvent(QQuickItem *item, QTouchEvent *event); #endif |