From 76ec5710d544dd19ef13c467bfcb1e441af56499 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 18 Feb 2014 17:13:48 +0100 Subject: Close popup windows when application state changes Nobody is telling the popup to close. If it was, that was probably as a side effect of the Qt::Popup flag on some platforms. Certainly not on Windows. We check for the application state as the application may use a popup to signal the user about some event happening, and we don't want to close the popup as soon as the user makes the application active again. Task-number: QTBUG-36474 Change-Id: If41f7bec696105e3c7d8897e9af5fc075c7b8933 Reviewed-by: J-P Nurmi Reviewed-by: Jens Bache-Wiig --- src/controls/qquickpopupwindow.cpp | 8 ++++++++ src/controls/qquickpopupwindow_p.h | 1 + 2 files changed, 9 insertions(+) diff --git a/src/controls/qquickpopupwindow.cpp b/src/controls/qquickpopupwindow.cpp index 02c50a85..7e36c8d1 100644 --- a/src/controls/qquickpopupwindow.cpp +++ b/src/controls/qquickpopupwindow.cpp @@ -54,6 +54,14 @@ QQuickPopupWindow::QQuickPopupWindow() : { setFlags(Qt::Popup); setModality(Qt::ApplicationModal); + connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)), + this, SLOT(applicationStateChanged(Qt::ApplicationState))); +} + +void QQuickPopupWindow::applicationStateChanged(Qt::ApplicationState state) +{ + if (state != Qt::ApplicationActive) + dismissPopup(); } void QQuickPopupWindow::show() diff --git a/src/controls/qquickpopupwindow_p.h b/src/controls/qquickpopupwindow_p.h index 65ce01a0..b4ce2b72 100644 --- a/src/controls/qquickpopupwindow_p.h +++ b/src/controls/qquickpopupwindow_p.h @@ -80,6 +80,7 @@ protected: protected Q_SLOTS: void updateSize(); + void applicationStateChanged(Qt::ApplicationState state); private: void forwardEventToTransientParent(QMouseEvent *); -- cgit v1.2.1