From bde6a049494f40cd71004d6926899f115af0c3e6 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 4 Oct 2018 10:34:21 +0200 Subject: [PATCH] QtWidgets: Fix Qt application coming to the foreground when launching app by popup menu Check on the application state before requesting activation. Fixes: QTBUG-70810 Change-Id: I550137dc00209b17f4b3c033287ceef1b871ff50 Reviewed-by: Shawn Rutledge --- src/widgets/kernel/qwidget.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 09a08fac14..6753c35cfc 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -6600,9 +6600,12 @@ QWidget *QWidgetPrivate::deepestFocusProxy() const void QWidgetPrivate::setFocus_sys() { Q_Q(QWidget); - // Embedded native widget may have taken the focus; get it back to toplevel if that is the case + // Embedded native widget may have taken the focus; get it back to toplevel + // if that is the case (QTBUG-25852) const QWidget *topLevel = q->window(); - if (topLevel->windowType() != Qt::Popup) { + // Do not activate in case the popup menu opens another application (QTBUG-70810). + if (QGuiApplication::applicationState() == Qt::ApplicationActive + && topLevel->windowType() != Qt::Popup) { if (QWindow *nativeWindow = q->window()->windowHandle()) { if (nativeWindow != QGuiApplication::focusWindow() && q->testAttribute(Qt::WA_WState_Created)) {