diff --git a/src/gui/kernel/qplatformmenu.h b/src/gui/kernel/qplatformmenu.h index e3fa5c71b1..28c29a704c 100644 --- a/src/gui/kernel/qplatformmenu.h +++ b/src/gui/kernel/qplatformmenu.h @@ -158,6 +158,7 @@ public: virtual void removeMenu(QPlatformMenu *menu) = 0; virtual void syncMenu(QPlatformMenu *menuItem) = 0; virtual void handleReparent(QWindow *newParentWindow) = 0; + virtual QWindow *parentWindow() const { return nullptr; } virtual QPlatformMenu *menuForTag(quintptr tag) const = 0; virtual QPlatformMenu *createMenu() const; diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.h b/src/plugins/platforms/cocoa/qcocoamenubar.h index 0ed653911a..50b6e69720 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.h +++ b/src/plugins/platforms/cocoa/qcocoamenubar.h @@ -60,6 +60,7 @@ public: void removeMenu(QPlatformMenu *menu) override; void syncMenu(QPlatformMenu *menuItem) override; void handleReparent(QWindow *newParentWindow) override; + QWindow *parentWindow() const override; QPlatformMenu *menuForTag(quintptr tag) const override; inline NSMenu *nsMenu() const diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.mm b/src/plugins/platforms/cocoa/qcocoamenubar.mm index 3564f0176e..30bff78a36 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.mm +++ b/src/plugins/platforms/cocoa/qcocoamenubar.mm @@ -241,6 +241,12 @@ void QCocoaMenuBar::handleReparent(QWindow *newParentWindow) updateMenuBarImmediately(); } +QWindow *QCocoaMenuBar::parentWindow() const +{ + return m_window ? m_window->window() : nullptr; +} + + QCocoaWindow *QCocoaMenuBar::findWindowForMenubar() { if (qApp->focusWindow()) diff --git a/src/widgets/kernel/qshortcut.cpp b/src/widgets/kernel/qshortcut.cpp index fde039c75e..a680ff7913 100644 --- a/src/widgets/kernel/qshortcut.cpp +++ b/src/widgets/kernel/qshortcut.cpp @@ -149,8 +149,16 @@ static bool correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidge bool visible = w->isVisible(); #if QT_CONFIG(menubar) if (QMenuBar *menuBar = qobject_cast(w)) { - if (menuBar->isNativeMenuBar()) - visible = true; + if (auto *pmb = menuBar->platformMenuBar()) { + if (menuBar->parentWidget()) { + visible = true; + } else { + if (auto *ww = qobject_cast(pmb->parentWindow())) + w = ww->widget(); // Good enough since we only care about the window + else + return false; // This is not a QWidget window. We won't deliver + } + } } #endif