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.

Pick-to: 6.4 6.3 6.2
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>
This commit is contained in:
Volker Hilsheimer 2022-08-19 10:40:10 +02:00
parent cf6ab64f03
commit 03144190df

View File

@ -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;