summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-08-19 10:40:10 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-08-23 21:50:42 +0000
commita6276ca0e410044d4ec8fa3f0d210149fc9e6387 (patch)
treec0d27d41839ea7361a6eb89cdc1a97868ff56465
parent1218e71aae83444f8b616dd4d3353266147ddd18 (diff)
Mac: close popups when the user clicks into the menubar
Otherwise it is possible to have a context menu and a menu from the menu bar open at the same time. Native applications close the context menu, but also block the click into the title bar. This change only closes popups, the click goes through to the menubar. Task-number: QTBUG-105474 Change-Id: I664c00eea83ba8fb43cc8a630d787f2d2b5b96ff Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> (cherry picked from commit 03144190dfa329444d8941781d20265dfe7ce59c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/plugins/platforms/cocoa/qcocoamenubar.mm7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.mm b/src/plugins/platforms/cocoa/qcocoamenubar.mm
index 23aae466df..341ffb6ffc 100644
--- a/src/plugins/platforms/cocoa/qcocoamenubar.mm
+++ b/src/plugins/platforms/cocoa/qcocoamenubar.mm
@@ -13,6 +13,8 @@
#include <QtGui/QGuiApplication>
#include <QtCore/QDebug>
+#include <QtGui/private/qguiapplication_p.h>
+
QT_BEGIN_NAMESPACE
static QList<QCocoaMenuBar*> static_menubars;
@@ -21,6 +23,11 @@ QCocoaMenuBar::QCocoaMenuBar()
{
static_menubars.append(this);
+ // clicks into the menu bar should close all popup windows
+ static QMacNotificationObserver menuBarClickObserver(nil, NSMenuDidBeginTrackingNotification, ^{
+ QGuiApplicationPrivate::instance()->closeAllPopups();
+ });
+
m_nativeMenu = [[NSMenu alloc] init];
#ifdef QT_COCOA_ENABLE_MENU_DEBUG
qDebug() << "Construct QCocoaMenuBar" << this << m_nativeMenu;