diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 3030e11f253..e0cee816454 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2033,11 +2033,26 @@ void QGuiApplicationPrivate::captureGlobalModifierState(QEvent *e) */ bool QGuiApplication::notify(QObject *object, QEvent *event) { + Q_D(QGuiApplication); if (object->isWindowType()) { if (QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(static_cast(object), event)) return true; // Platform plugin ate the event } + switch (event->type()) { + case QEvent::ApplicationDeactivate: + case QEvent::OrientationChange: + // Close all popups (triggers when switching applications + // by pressing ALT-TAB on Windows, which is not received as a key event. + // triggers when the screen rotates.) + // This is also necessary on Wayland, and platforms where + // QWindow::setMouseGrabEnabled(true) doesn't work. + d->closeAllPopups(); + break; + default: + break; + } + QGuiApplicationPrivate::captureGlobalModifierState(event); return QCoreApplication::notify(object, event);