diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2012-10-18 14:15:38 +0300 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-10-19 13:02:17 +0200 |
commit | bdc0eaae6b47eebbf99bea1034857287fb75aa46 (patch) | |
tree | 7afe9f38f88dc22a09e21be0b3e4e58d166e806b /src/widgets | |
parent | f948294f5ebbfd39ac802712aa9747d73738235b (diff) |
Fix excess enter/leave event generation for native widgets
Native widgets have a native window each, so QPA plugin sends enter and
leave events for associated QWindow whenever mouse cursor moves from
one widget to another. QWidgetWindow had no context to interpret these
events as moves from one widget to another, since they were sent
separately. This resulted in leaves and enters for each widget in
parent chain, when only the bottom child should have gotten them.
Fixed by peeking into window system message queue when handling leave
in QWidgetWindow and retrieving the entered window from queued enter
event.
Also provided a convenience function that QPA plugin can use to
ensure both leave and enter events are in the event queue when
moving from one QWindow to another.
Task-number: QTBUG-27550
Change-Id: I74fec0ac90f6848495c2392c5f7e41624ad8aea2
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/kernel/qwidgetwindow.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index 10ec4d3745..5f25e1274e 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -47,6 +47,7 @@ #include <QtGui/qaccessible.h> #endif #include <private/qwidgetbackingstore_p.h> +#include <qpa/qwindowsysteminterface_p.h> QT_BEGIN_NAMESPACE @@ -212,9 +213,31 @@ QPointer<QWidget> qt_last_mouse_receiver = 0; void QWidgetWindow::handleEnterLeaveEvent(QEvent *event) { if (event->type() == QEvent::Leave) { + QWidget *enter = 0; + // Check from window system event queue if the next queued enter targets a window + // in the same window hierarchy (e.g. enter a child of this window). If so, + // remove the enter event from queue and handle both in single dispatch. + QWindowSystemInterfacePrivate::EnterEvent *systemEvent = + static_cast<QWindowSystemInterfacePrivate::EnterEvent *> + (QWindowSystemInterfacePrivate::peekWindowSystemEvent(QWindowSystemInterfacePrivate::Enter)); + if (systemEvent) { + if (QWidgetWindow *enterWindow = qobject_cast<QWidgetWindow *>(systemEvent->enter)) + { + QWindow *thisParent = this; + QWindow *enterParent = enterWindow; + while (thisParent->parent()) + thisParent = thisParent->parent(); + while (enterParent->parent()) + enterParent = enterParent->parent(); + if (thisParent == enterParent) { + enter = enterWindow->widget(); + QWindowSystemInterfacePrivate::removeWindowSystemEvent(systemEvent); + } + } + } QWidget *leave = qt_last_mouse_receiver ? qt_last_mouse_receiver.data() : m_widget; - QApplicationPrivate::dispatchEnterLeave(0, leave); - qt_last_mouse_receiver = 0; + QApplicationPrivate::dispatchEnterLeave(enter, leave); + qt_last_mouse_receiver = enter; } else { QApplicationPrivate::dispatchEnterLeave(m_widget, 0); qt_last_mouse_receiver = m_widget; |