summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorDmitry Shachnev <mitya57@gmail.com>2016-11-02 10:51:39 +0300
committerShawn Rutledge <shawn.rutledge@qt.io>2017-01-19 08:41:55 +0000
commit287f548d4c7cc594ffecc9c050dc5ec9fdaa6d37 (patch)
tree988f18cc12271bd84946837e0da215d3de98fb13 /src/widgets
parent3e31b71b9ca859cad8823a9d8d19063dd14be809 (diff)
Make shortcuts work for platform menu bars
When a platform menu bar is used, the QMenuBar is hidden, so shortcuts for QActions attached only to it do not work. Extend the macOS-specific code to treat such menubars as visible to other platforms, to make the shortcuts work. The exception is made for internal QMenuBar shortcuts, which are forwarded to the platform menu. A follow-up change will add support for this to QDBusPlatformMenu. The updateGeometries() method is called for platform menu bars too to make sure the internal shortcuts are registered even if the global menu is in use. Add two cases to the tst_QMenuBar::activatedCount() test to test both native and non-native menu bars when possible (it now passes with native menu bars too). Change-Id: I2d7128512719ac199cd3f8f7ba28333d04d84ed4 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/kernel/qshortcut.cpp8
-rw-r--r--src/widgets/widgets/qmenubar.cpp13
2 files changed, 16 insertions, 5 deletions
diff --git a/src/widgets/kernel/qshortcut.cpp b/src/widgets/kernel/qshortcut.cpp
index 6eec5ff7e8..be5788274e 100644
--- a/src/widgets/kernel/qshortcut.cpp
+++ b/src/widgets/kernel/qshortcut.cpp
@@ -141,9 +141,11 @@ bool qWidgetShortcutContextMatcher(QObject *object, Qt::ShortcutContext context)
static bool correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidget *active_window)
{
bool visible = w->isVisible();
-#if defined(Q_OS_DARWIN) && !defined(QT_NO_MENUBAR)
- if (!qApp->testAttribute(Qt::AA_DontUseNativeMenuBar) && qobject_cast<QMenuBar *>(w))
- visible = true;
+#ifndef QT_NO_MENUBAR
+ if (QMenuBar *menuBar = qobject_cast<QMenuBar *>(w)) {
+ if (menuBar->isNativeMenuBar())
+ visible = true;
+ }
#endif
if (!visible || !w->isEnabled())
diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp
index 63fe09f77e..2588f41468 100644
--- a/src/widgets/widgets/qmenubar.cpp
+++ b/src/widgets/widgets/qmenubar.cpp
@@ -1271,10 +1271,12 @@ void QMenuBar::actionEvent(QActionEvent *e)
} else if(e->type() == QEvent::ActionRemoved) {
e->action()->disconnect(this);
}
- if (isVisible()) {
+ // updateGeometries() is also needed for native menu bars because
+ // it updates shortcutIndexMap
+ if (isVisible() || isNativeMenuBar())
d->updateGeometries();
+ if (isVisible())
update();
- }
}
/*!
@@ -1686,6 +1688,13 @@ void QMenuBarPrivate::_q_internalShortcutActivated(int id)
{
Q_Q(QMenuBar);
QAction *act = actions.at(id);
+ if (act && act->menu()) {
+ if (QPlatformMenu *platformMenu = act->menu()->platformMenu()) {
+ platformMenu->showPopup(q->windowHandle(), actionRects.at(id), Q_NULLPTR);
+ return;
+ }
+ }
+
setCurrentAction(act, true, true);
if (act && !act->menu()) {
activateAction(act, QAction::Trigger);