summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/kernel/qwidgetwindow.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp
index d40fc84d77..1cd042f99d 100644
--- a/src/widgets/kernel/qwidgetwindow.cpp
+++ b/src/widgets/kernel/qwidgetwindow.cpp
@@ -433,14 +433,19 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
QWindow *win = w->windowHandle();
if (!win)
win = w->nativeParentWidget()->windowHandle();
- if (win && win->geometry().contains(event->globalPos())) {
- // Use postEvent() to ensure the local QEventLoop terminates when called from QMenu::exec()
- const QPoint localPos = win->mapFromGlobal(event->globalPos());
- QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonPress, localPos, localPos, event->globalPos(), event->button(), event->buttons(), event->modifiers());
- QCoreApplicationPrivate::setEventSpontaneous(e, true);
- QGuiApplicationPrivate::setMouseEventSource(e, QGuiApplicationPrivate::mouseEventSource(event));
- e->setTimestamp(event->timestamp());
- QCoreApplication::postEvent(win, e);
+ if (win) {
+ const QRect globalGeometry = win->isTopLevel()
+ ? win->geometry()
+ : QRect(win->mapToGlobal(QPoint(0, 0)), win->size());
+ if (globalGeometry.contains(event->globalPos())) {
+ // Use postEvent() to ensure the local QEventLoop terminates when called from QMenu::exec()
+ const QPoint localPos = win->mapFromGlobal(event->globalPos());
+ QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonPress, localPos, localPos, event->globalPos(), event->button(), event->buttons(), event->modifiers());
+ QCoreApplicationPrivate::setEventSpontaneous(e, true);
+ QGuiApplicationPrivate::setMouseEventSource(e, QGuiApplicationPrivate::mouseEventSource(event));
+ e->setTimestamp(event->timestamp());
+ QCoreApplication::postEvent(win, e);
+ }
}
}
}