summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/kernel/qcoreevent.cpp2
-rw-r--r--src/gui/kernel/qevent.cpp34
-rw-r--r--src/gui/kernel/qevent.h22
-rw-r--r--src/gui/kernel/qguiapplication.cpp2
-rw-r--r--src/gui/kernel/qwindowsysteminterface.cpp8
-rw-r--r--src/gui/kernel/qwindowsysteminterface.h4
-rw-r--r--src/gui/kernel/qwindowsysteminterface_p.h6
-rw-r--r--src/plugins/platforms/cocoa/qnsview.mm23
-rw-r--r--src/plugins/platforms/windows/qwindowsmousehandler.cpp4
-rw-r--r--src/plugins/platforms/xcb/qxcbwindow.cpp4
-rw-r--r--src/widgets/graphicsview/qgraphicsproxywidget.cpp8
-rw-r--r--src/widgets/kernel/qapplication.cpp40
-rw-r--r--src/widgets/kernel/qapplication_p.h2
-rw-r--r--src/widgets/kernel/qapplication_qpa.cpp3
-rw-r--r--src/widgets/kernel/qwidget.cpp2
-rw-r--r--src/widgets/kernel/qwidgetwindow.cpp6
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp21
-rw-r--r--tests/manual/widgetgrab/main.cpp4
18 files changed, 138 insertions, 57 deletions
diff --git a/src/corelib/kernel/qcoreevent.cpp b/src/corelib/kernel/qcoreevent.cpp
index c0292ee984..b9136b5335 100644
--- a/src/corelib/kernel/qcoreevent.cpp
+++ b/src/corelib/kernel/qcoreevent.cpp
@@ -121,7 +121,7 @@ QT_BEGIN_NAMESPACE
\value Drop A drag and drop operation is completed (QDropEvent).
\value DynamicPropertyChange A dynamic property was added, changed, or removed from the object.
\value EnabledChange Widget's enabled state has changed.
- \value Enter Mouse enters widget's boundaries.
+ \value Enter Mouse enters widget's boundaries (QEnterEvent).
\value EnterEditFocus An editor widget gains focus for editing. QT_KEYPAD_NAVIGATION must be defined.
\value EnterWhatsThisMode Send to toplevel widgets when the application enters "What's This?" mode.
\value Expose Sent to a window when its on-screen contents are invalidated and need to be flushed from the backing store.
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 3dbef228a5..66434f9a53 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -56,6 +56,40 @@
QT_BEGIN_NAMESPACE
/*!
+ \class QEnterEvent
+ \ingroup events
+
+ \brief The QEnterEvent class contains parameters that describe an enter event.
+
+ Enter events occur when the mouse cursor enters a window or a widget.
+
+ \since 5.0
+*/
+
+/*!
+ Constructs an enter event object.
+
+ The points \a localPos, \a windowPos and \a screenPos specify the
+ mouse cursor's position relative to the receiving widget or item,
+ window, and screen, respectively.
+*/
+
+QEnterEvent::QEnterEvent(const QPointF &localPos, const QPointF &windowPos, const QPointF &screenPos)
+ : QEvent(QEvent::Enter)
+ , l(localPos)
+ , w(windowPos)
+ , s(screenPos)
+{
+}
+
+/*!
+ \internal
+*/
+QEnterEvent::~QEnterEvent()
+{
+}
+
+/*!
\class QInputEvent
\ingroup events
\inmodule QtGui
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h
index b35dd88c2a..82d22aec05 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -83,6 +83,28 @@ protected:
ulong ts;
};
+class Q_GUI_EXPORT QEnterEvent : public QEvent
+{
+public:
+ QEnterEvent(const QPointF &localPos, const QPointF &windowPos, const QPointF &screenPos);
+ ~QEnterEvent();
+
+#ifndef QT_NO_INTEGER_EVENT_COORDINATES
+ inline QPoint pos() const { return l.toPoint(); }
+ inline QPoint globalPos() const { return s.toPoint(); }
+ inline int x() const { return qRound(l.x()); }
+ inline int y() const { return qRound(l.y()); }
+ inline int globalX() const { return qRound(s.x()); }
+ inline int globalY() const { return qRound(s.y()); }
+#endif
+ const QPointF &localPos() const { return l; }
+ const QPointF &windowPos() const { return w; }
+ const QPointF &screenPos() const { return s; }
+
+protected:
+ QPointF l, w, s;
+};
+
class Q_GUI_EXPORT QMouseEvent : public QInputEvent
{
public:
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index ca9d60fcdf..4c4e75c4f6 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -1424,7 +1424,7 @@ void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::En
currentMouseWindow = e->enter;
- QEvent event(QEvent::Enter);
+ QEnterEvent event(e->localPos, e->localPos, e->globalPos);
QCoreApplication::sendSpontaneousEvent(e->enter.data(), &event);
}
diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp
index 6fb10b6c75..acc6eace99 100644
--- a/src/gui/kernel/qwindowsysteminterface.cpp
+++ b/src/gui/kernel/qwindowsysteminterface.cpp
@@ -75,10 +75,10 @@ extern QPointer<QWindow> qt_last_mouse_receiver;
until sendWindowSystemEvents() is called by the event dispatcher.
*/
-void QWindowSystemInterface::handleEnterEvent(QWindow *tlw)
+void QWindowSystemInterface::handleEnterEvent(QWindow *tlw, const QPointF &local, const QPointF &global)
{
if (tlw) {
- QWindowSystemInterfacePrivate::EnterEvent *e = new QWindowSystemInterfacePrivate::EnterEvent(tlw);
+ QWindowSystemInterfacePrivate::EnterEvent *e = new QWindowSystemInterfacePrivate::EnterEvent(tlw, local, global);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
}
}
@@ -96,13 +96,13 @@ void QWindowSystemInterface::handleLeaveEvent(QWindow *tlw)
determine where mouse went and act accordingly. E.g. QWidgetWindow needs to know if mouse
cursor moves between windows in same window hierarchy.
*/
-void QWindowSystemInterface::handleEnterLeaveEvent(QWindow *enter, QWindow *leave)
+void QWindowSystemInterface::handleEnterLeaveEvent(QWindow *enter, QWindow *leave, const QPointF &local, const QPointF& global)
{
bool wasSynchronous = QWindowSystemInterfacePrivate::synchronousWindowsSystemEvents;
if (wasSynchronous)
setSynchronousWindowsSystemEvents(false);
handleLeaveEvent(leave);
- handleEnterEvent(enter);
+ handleEnterEvent(enter, local, global);
if (wasSynchronous) {
flushWindowSystemEvents();
setSynchronousWindowsSystemEvents(true);
diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h
index b4b2e845fc..a3d2f1b000 100644
--- a/src/gui/kernel/qwindowsysteminterface.h
+++ b/src/gui/kernel/qwindowsysteminterface.h
@@ -134,9 +134,9 @@ public:
static void handleGeometryChange(QWindow *w, const QRect &newRect);
static void handleCloseEvent(QWindow *w);
- static void handleEnterEvent(QWindow *w);
+ static void handleEnterEvent(QWindow *w, const QPointF &local = QPointF(), const QPointF& global = QPointF());
static void handleLeaveEvent(QWindow *w);
- static void handleEnterLeaveEvent(QWindow *enter, QWindow *leave);
+ static void handleEnterLeaveEvent(QWindow *enter, QWindow *leave, const QPointF &local = QPointF(), const QPointF& global = QPointF());
static void handleWindowActivated(QWindow *w);
static void handleWindowStateChanged(QWindow *w, Qt::WindowState newState);
diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h
index 5867337de6..b174fd0ca2 100644
--- a/src/gui/kernel/qwindowsysteminterface_p.h
+++ b/src/gui/kernel/qwindowsysteminterface_p.h
@@ -119,10 +119,12 @@ public:
class EnterEvent : public WindowSystemEvent {
public:
- explicit EnterEvent(QWindow *enter)
- : WindowSystemEvent(Enter), enter(enter)
+ explicit EnterEvent(QWindow *enter, const QPointF &local, const QPointF &global)
+ : WindowSystemEvent(Enter), enter(enter), localPos(local), globalPos(global)
{ }
QPointer<QWindow> enter;
+ const QPointF localPos;
+ const QPointF globalPos;
};
class LeaveEvent : public WindowSystemEvent {
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index bbd74dd58b..4fb099341e 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -340,7 +340,7 @@ static CGImageRef qt_mac_toCGImage(QImage *qImage, bool isMask, uchar **dataCopy
return YES;
}
-- (void)handleMouseEvent:(NSEvent *)theEvent
+- (void)convertFromEvent:(NSEvent *)event toWindowPoint:(QPoint *)qtWindowPoint andScreenPoint:(QPoint *)qtScreenPoint
{
// Calculate the mouse position in the QWindow and Qt screen coordinate system,
// starting from coordinates in the NSWindow coordinate system.
@@ -360,25 +360,29 @@ static CGImageRef qt_mac_toCGImage(QImage *qImage, bool isMask, uchar **dataCopy
// NSView and QWindow are equal coordinate systems: the QWindow covers the
// entire NSView, and we've set the NSView's isFlipped property to true.
- NSPoint nsWindowPoint = [theEvent locationInWindow]; // NSWindow coordinates
+ NSPoint nsWindowPoint = [event locationInWindow]; // NSWindow coordinates
NSPoint nsViewPoint = [self convertPoint: nsWindowPoint fromView: nil]; // NSView/QWindow coordinates
- QPoint qtWindowPoint(nsViewPoint.x, nsViewPoint.y); // NSView/QWindow coordinates
-
- QPoint qtScreenPoint;
+ *qtWindowPoint = QPoint(nsViewPoint.x, nsViewPoint.y); // NSView/QWindow coordinates
NSWindow *window = [self window];
// Use convertRectToScreen if available (added in 10.7).
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
if ([window respondsToSelector:@selector(convertRectToScreen:)]) {
NSRect screenRect = [window convertRectToScreen : NSMakeRect(nsWindowPoint.x, nsWindowPoint.y, 0, 0)]; // OS X screen coordinates
- qtScreenPoint = QPoint(screenRect.origin.x, qt_mac_flipYCoordinate(screenRect.origin.y)); // Qt screen coordinates
+ *qtScreenPoint = QPoint(screenRect.origin.x, qt_mac_flipYCoordinate(screenRect.origin.y)); // Qt screen coordinates
} else
#endif
{
NSPoint screenPoint = [window convertBaseToScreen : NSMakePoint(nsWindowPoint.x, nsWindowPoint.y)];
- qtScreenPoint = QPoint(screenPoint.x, qt_mac_flipYCoordinate(screenPoint.y));
+ *qtScreenPoint = QPoint(screenPoint.x, qt_mac_flipYCoordinate(screenPoint.y));
}
+}
+
+- (void)handleMouseEvent:(NSEvent *)theEvent
+{
+ QPoint qtWindowPoint, qtScreenPoint;
+ [self convertFromEvent:theEvent toWindowPoint:&qtWindowPoint andScreenPoint:&qtScreenPoint];
ulong timestamp = [theEvent timestamp] * 1000;
QCocoaDrag* nativeDrag = static_cast<QCocoaDrag *>(QGuiApplicationPrivate::platformIntegration()->drag());
@@ -463,8 +467,9 @@ static CGImageRef qt_mac_toCGImage(QImage *qImage, bool isMask, uchar **dataCopy
- (void)mouseEntered:(NSEvent *)theEvent
{
- Q_UNUSED(theEvent);
- QWindowSystemInterface::handleEnterEvent(m_window);
+ QPoint windowPoint, screenPoint;
+ [self convertFromEvent:theEvent toWindowPoint:&windowPoint andScreenPoint:&screenPoint];
+ QWindowSystemInterface::handleEnterEvent(m_window, windowPoint, screenPoint);
}
- (void)mouseExited:(NSEvent *)theEvent
diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.cpp b/src/plugins/platforms/windows/qwindowsmousehandler.cpp
index 024a273022..0fb67d0e98 100644
--- a/src/plugins/platforms/windows/qwindowsmousehandler.cpp
+++ b/src/plugins/platforms/windows/qwindowsmousehandler.cpp
@@ -291,7 +291,9 @@ bool QWindowsMouseHandler::translateMouseEvent(QWindow *window, HWND hwnd,
if (QWindowsContext::verboseEvents)
qDebug() << "Entering " << currentWindowUnderMouse;
QWindowsWindow::baseWindowOf(currentWindowUnderMouse)->applyCursor();
- QWindowSystemInterface::handleEnterEvent(currentWindowUnderMouse);
+ QWindowSystemInterface::handleEnterEvent(currentWindowUnderMouse,
+ currentWindowUnderMouse->mapFromGlobal(globalPosition),
+ globalPosition);
}
}
m_windowUnderMouse = currentWindowUnderMouse;
diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp
index 81ab3fe4ee..b6bbbdcc30 100644
--- a/src/plugins/platforms/xcb/qxcbwindow.cpp
+++ b/src/plugins/platforms/xcb/qxcbwindow.cpp
@@ -1529,7 +1529,9 @@ void QXcbWindow::handleEnterNotifyEvent(const xcb_enter_notify_event_t *event)
return;
}
- QWindowSystemInterface::handleEnterEvent(window());
+ const QPoint local(event->event_x, event->event_y);
+ const QPoint global(event->root_x, event->root_y);
+ QWindowSystemInterface::handleEnterEvent(window(), local, global);
}
void QXcbWindow::handleLeaveNotifyEvent(const xcb_leave_notify_event_t *event)
diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.cpp b/src/widgets/graphicsview/qgraphicsproxywidget.cpp
index 762f93f55b..289f9919ef 100644
--- a/src/widgets/graphicsview/qgraphicsproxywidget.cpp
+++ b/src/widgets/graphicsview/qgraphicsproxywidget.cpp
@@ -267,7 +267,7 @@ void QGraphicsProxyWidgetPrivate::sendWidgetMouseEvent(QGraphicsSceneMouseEvent
}
if (!lastWidgetUnderMouse) {
- QApplicationPrivate::dispatchEnterLeave(embeddedMouseGrabber ? embeddedMouseGrabber : receiver, 0);
+ QApplicationPrivate::dispatchEnterLeave(embeddedMouseGrabber ? embeddedMouseGrabber : receiver, 0, event->screenPos());
lastWidgetUnderMouse = receiver;
}
@@ -293,7 +293,7 @@ void QGraphicsProxyWidgetPrivate::sendWidgetMouseEvent(QGraphicsSceneMouseEvent
else // released on the frame our outside the item, or doesn't accept hover events.
lastWidgetUnderMouse = 0;
- QApplicationPrivate::dispatchEnterLeave(lastWidgetUnderMouse, embeddedMouseGrabber);
+ QApplicationPrivate::dispatchEnterLeave(lastWidgetUnderMouse, embeddedMouseGrabber, event->screenPos());
embeddedMouseGrabber = 0;
#ifndef QT_NO_CURSOR
@@ -1142,7 +1142,7 @@ void QGraphicsProxyWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Q_D(QGraphicsProxyWidget);
// If hoverMove was compressed away, make sure we update properly here.
if (d->lastWidgetUnderMouse) {
- QApplicationPrivate::dispatchEnterLeave(0, d->lastWidgetUnderMouse);
+ QApplicationPrivate::dispatchEnterLeave(0, d->lastWidgetUnderMouse, event->screenPos());
d->lastWidgetUnderMouse = 0;
}
}
@@ -1159,7 +1159,7 @@ void QGraphicsProxyWidget::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
// Ignore events on the window frame.
if (!d->widget || !rect().contains(event->pos())) {
if (d->lastWidgetUnderMouse) {
- QApplicationPrivate::dispatchEnterLeave(0, d->lastWidgetUnderMouse);
+ QApplicationPrivate::dispatchEnterLeave(0, d->lastWidgetUnderMouse, event->screenPos());
d->lastWidgetUnderMouse = 0;
}
return;
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index aeceba1886..d62b8ef146 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -2114,20 +2114,23 @@ QWidget *QApplicationPrivate::focusNextPrevChild_helper(QWidget *toplevel, bool
}
/*!
- \fn void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave)
+ \fn void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, const QPointF &globalPosF)
\internal
Creates the proper Enter/Leave event when widget \a enter is entered and
widget \a leave is left.
*/
-void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave) {
+void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave, const QPointF &globalPosF)
+{
+ const QPoint globalPos = globalPosF.toPoint();
#if 0
if (leave) {
QEvent e(QEvent::Leave);
QApplication::sendEvent(leave, & e);
}
if (enter) {
- QEvent e(QEvent::Enter);
+ const QPoint windowPos = enter->window()->mapFromGlobal(globalPos);
+ QEnterEvent e(enter->mapFromGlobal(globalPos), windowPos, globalPos);
QApplication::sendEvent(enter, & e);
}
return;
@@ -2205,17 +2208,20 @@ void QApplicationPrivate::dispatchEnterLeave(QWidget* enter, QWidget* leave) {
}
}
}
- QPoint posEnter = QCursor::pos();
- QEvent enterEvent(QEvent::Enter);
- for (int i = 0; i < enterList.size(); ++i) {
- w = enterList.at(i);
- if (!QApplication::activeModalWidget() || QApplicationPrivate::tryModalHelper(w, 0)) {
- QApplication::sendEvent(w, &enterEvent);
- if (w->testAttribute(Qt::WA_Hover) &&
- (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == w->window())) {
- QHoverEvent he(QEvent::HoverEnter, w->mapFromGlobal(posEnter), QPoint(-1, -1),
- QApplication::keyboardModifiers());
- qApp->d_func()->notify_helper(w, &he);
+ if (!enterList.isEmpty()) {
+ const QPoint windowPos = enterList.front()->window()->mapFromGlobal(globalPos);
+ for (int i = 0; i < enterList.size(); ++i) {
+ w = enterList.at(i);
+ if (!QApplication::activeModalWidget() || QApplicationPrivate::tryModalHelper(w, 0)) {
+ const QPointF localPos = w->mapFromGlobal(globalPos);
+ QEnterEvent enterEvent(localPos, windowPos, globalPosF);
+ QApplication::sendEvent(w, &enterEvent);
+ if (w->testAttribute(Qt::WA_Hover) &&
+ (!QApplication::activePopupWidget() || QApplication::activePopupWidget() == w->window())) {
+ QHoverEvent he(QEvent::HoverEnter, localPos, QPoint(-1, -1),
+ QApplication::keyboardModifiers());
+ qApp->d_func()->notify_helper(w, &he);
+ }
}
}
}
@@ -2506,9 +2512,9 @@ bool QApplicationPrivate::sendMouseEvent(QWidget *receiver, QMouseEvent *event,
|| (isAlien(lastMouseReceiver) && !alienWidget)) {
if (activePopupWidget) {
if (!QWidget::mouseGrabber())
- dispatchEnterLeave(alienWidget ? alienWidget : nativeWidget, lastMouseReceiver);
+ dispatchEnterLeave(alienWidget ? alienWidget : nativeWidget, lastMouseReceiver, event->screenPos());
} else {
- dispatchEnterLeave(receiver, lastMouseReceiver);
+ dispatchEnterLeave(receiver, lastMouseReceiver, event->screenPos());
}
}
@@ -2540,7 +2546,7 @@ bool QApplicationPrivate::sendMouseEvent(QWidget *receiver, QMouseEvent *event,
enter = alienGuard ? alienWidget : nativeWidget;
else // The receiver is typically deleted on mouse release with drag'n'drop.
enter = QApplication::widgetAt(event->globalPos());
- dispatchEnterLeave(enter, leaveAfterRelease);
+ dispatchEnterLeave(enter, leaveAfterRelease, event->screenPos());
leaveAfterRelease = 0;
lastMouseReceiver = enter;
} else if (!wasLeaveAfterRelease) {
diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h
index 5682d794cf..5b3493f478 100644
--- a/src/widgets/kernel/qapplication_p.h
+++ b/src/widgets/kernel/qapplication_p.h
@@ -135,7 +135,7 @@ public:
void createEventDispatcher();
- static void dispatchEnterLeave(QWidget *enter, QWidget *leave);
+ static void dispatchEnterLeave(QWidget *enter, QWidget *leave, const QPointF &globalPosF);
//modality
bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = 0) const Q_DECL_OVERRIDE;
diff --git a/src/widgets/kernel/qapplication_qpa.cpp b/src/widgets/kernel/qapplication_qpa.cpp
index 5dc68e47e0..e8db364473 100644
--- a/src/widgets/kernel/qapplication_qpa.cpp
+++ b/src/widgets/kernel/qapplication_qpa.cpp
@@ -253,7 +253,8 @@ void QApplicationPrivate::openPopup(QWidget *popup)
// Dispatch leave for last mouse receiver to update undermouse states
if (qt_last_mouse_receiver && !QWidget::mouseGrabber()) {
- QApplicationPrivate::dispatchEnterLeave(0, qt_last_mouse_receiver.data());
+ QApplicationPrivate::dispatchEnterLeave(0, qt_last_mouse_receiver.data(),
+ QGuiApplicationPrivate::lastCursorPosition);
qt_last_mouse_receiver = 0;
}
}
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index 2feb797985..be2a5f36cd 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -8563,6 +8563,8 @@ void QWidget::enterEvent(QEvent *)
{
}
+// ### Qt 6: void QWidget::enterEvent(QEnterEvent *).
+
/*!
\fn void QWidget::leaveEvent(QEvent *event)
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp
index 1cabb095ec..c11e36312f 100644
--- a/src/widgets/kernel/qwidgetwindow.cpp
+++ b/src/widgets/kernel/qwidgetwindow.cpp
@@ -230,6 +230,7 @@ void QWidgetWindow::handleEnterLeaveEvent(QEvent *event)
QWindowSystemInterfacePrivate::EnterEvent *systemEvent =
static_cast<QWindowSystemInterfacePrivate::EnterEvent *>
(QWindowSystemInterfacePrivate::peekWindowSystemEvent(QWindowSystemInterfacePrivate::Enter));
+ const QPointF globalPosF = systemEvent ? systemEvent->globalPos : QGuiApplicationPrivate::lastCursorPosition;
if (systemEvent) {
if (QWidgetWindow *enterWindow = qobject_cast<QWidgetWindow *>(systemEvent->enter))
{
@@ -255,11 +256,12 @@ void QWidgetWindow::handleEnterLeaveEvent(QEvent *event)
QWidget *leave = m_widget;
if (qt_last_mouse_receiver && !qt_last_mouse_receiver->internalWinId())
leave = qt_last_mouse_receiver.data();
- QApplicationPrivate::dispatchEnterLeave(enter, leave);
+ QApplicationPrivate::dispatchEnterLeave(enter, leave, globalPosF);
qt_last_mouse_receiver = enter;
}
} else {
- QApplicationPrivate::dispatchEnterLeave(m_widget, 0);
+ const QEnterEvent *ee = static_cast<QEnterEvent *>(event);
+ QApplicationPrivate::dispatchEnterLeave(m_widget, 0, ee->screenPos());
qt_last_mouse_receiver = m_widget;
}
}
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 7de3f8aced..a70129c5f7 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -5407,6 +5407,7 @@ void tst_QWidget::setToolTip()
// Mouse over doesn't work on Windows mobile, so skip the rest of the test for that platform.
#ifndef Q_OS_WINCE_WM
for (int pass = 0; pass < 2; ++pass) {
+ QCursor::setPos(0, 0);
QScopedPointer<QWidget> popup(new QWidget(0, Qt::Popup));
popup->setObjectName(QString::fromLatin1("tst_qwidget setToolTip #%1").arg(pass));
popup->setWindowTitle(popup->objectName());
@@ -5421,17 +5422,16 @@ void tst_QWidget::setToolTip()
popup->setToolTip(QLatin1String("TOOLTIP POPUP"));
popup->show();
QVERIFY(QTest::qWaitForWindowExposed(popup.data()));
+ QWindow *popupWindow = popup->windowHandle();
QTest::qWait(10);
- QTest::mouseMove(frame);
+ QTest::mouseMove(popupWindow, QPoint(25, 25));
QTest::qWait(900); // delay is 700
- if (m_platform == QStringLiteral("xcb"))
- QSKIP("QTBUG-26424");
QCOMPARE(spy1.count(), 1);
QCOMPARE(spy2.count(), 0);
if (pass == 0)
QTest::qWait(2200); // delay is 2000
- QTest::mouseMove(popup.data());
+ QTest::mouseMove(popupWindow);
}
#endif
}
@@ -9635,7 +9635,7 @@ void tst_QWidget::underMouse()
// Enter window, outside children
// Note: QTest::mouseMove will not generate enter events for windows, so send one explicitly
- QWindowSystemInterface::handleEnterEvent(window);
+ QWindowSystemInterface::handleEnterEvent(window, inWindowPoint, window->mapToGlobal(inWindowPoint));
QTest::mouseMove(window, inWindowPoint);
QVERIFY(topLevelWidget.underMouse());
QVERIFY(!childWidget1.underMouse());
@@ -9754,7 +9754,7 @@ void tst_QWidget::underMouse()
childWidget1.resetCounts();
// Mouse enters back in, should cause enter to topLevelWidget
- QWindowSystemInterface::handleEnterEvent(window);
+ QWindowSystemInterface::handleEnterEvent(window, inWindowPoint, window->mapToGlobal(inWindowPoint));
QApplication::processEvents();
QVERIFY(!topLevelWidget.underMouse());
QVERIFY(!childWidget1.underMouse());
@@ -9788,7 +9788,8 @@ void tst_QWidget::underMouse()
// Mouse enters popup, should cause enter to popup and leave to current widgets under mouse
QWindowSystemInterface::handleLeaveEvent(window);
- QWindowSystemInterface::handleEnterEvent(popupWindow);
+ const QPoint popupCenter = popupWindow->geometry().center();
+ QWindowSystemInterface::handleEnterEvent(popupWindow, popupWindow->mapFromGlobal(popupCenter), popupCenter);
QApplication::processEvents();
QVERIFY(!topLevelWidget.underMouse());
QVERIFY(!childWidget1.underMouse());
@@ -9823,7 +9824,7 @@ void tst_QWidget::underMouse()
// Mouse leaves popup and enters topLevelWidget, should cause enter to topLevelWidget and leave for popup
QWindowSystemInterface::handleLeaveEvent(popupWindow);
- QWindowSystemInterface::handleEnterEvent(window);
+ QWindowSystemInterface::handleEnterEvent(window, inWindowPoint, window->mapToGlobal(inWindowPoint));
QApplication::processEvents();
QVERIFY(!topLevelWidget.underMouse());
QVERIFY(!childWidget1.underMouse());
@@ -9876,7 +9877,7 @@ public slots:
QPoint point2(15, 20);
QPoint point3(20, 20);
QWindow *window = modal->windowHandle();
- QWindowSystemInterface::handleEnterEvent(window);
+ QWindowSystemInterface::handleEnterEvent(window, point1, window->mapToGlobal(point1));
QTest::mouseMove(window, point1);
QTest::mouseMove(window, point2);
QTest::mouseMove(window, point3);
@@ -9922,7 +9923,7 @@ void tst_QWidget::taskQTBUG_27643_enterEvents()
QWindow *window = dialog.windowHandle();
QPoint overButton(25, 25);
- QWindowSystemInterface::handleEnterEvent(window);
+ QWindowSystemInterface::handleEnterEvent(window, overButton, window->mapToGlobal(overButton));
QTest::mouseMove(window, overButton);
QTest::mouseClick(window, Qt::LeftButton, 0, overButton, 0);
diff --git a/tests/manual/widgetgrab/main.cpp b/tests/manual/widgetgrab/main.cpp
index e03800ee6d..a83338e9b7 100644
--- a/tests/manual/widgetgrab/main.cpp
+++ b/tests/manual/widgetgrab/main.cpp
@@ -233,9 +233,11 @@ bool MainWindow::eventFilter(QObject *o, QEvent *e)
if (o->isWidgetType()) {
switch (e->type()) {
case QEvent::Enter: {
+ const QEnterEvent *ee = static_cast<QEnterEvent *>(e);
QString message;
QDebug debug(&message);
- debug.nospace() << '#' << m_enterLeaveEventCount++ << " Enter for " << o->objectName();
+ debug.nospace() << '#' << m_enterLeaveEventCount++ << " Enter for " << o->objectName()
+ << " at " << ee->localPos() << " global: " << ee->globalPos();
m_logEdit->appendPlainText(message);
}
break;