diff options
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/widgets/qmenubar.cpp | 21 | ||||
-rw-r--r-- | src/widgets/widgets/qmenubar_p.h | 1 |
2 files changed, 15 insertions, 7 deletions
diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp index 8fb02aaa72..85d0c54357 100644 --- a/src/widgets/widgets/qmenubar.cpp +++ b/src/widgets/widgets/qmenubar.cpp @@ -1210,12 +1210,19 @@ void QMenuBar::leaveEvent(QEvent *) d->setCurrentAction(0); } -QPlatformMenu *getPlatformMenu(QAction *action) +QPlatformMenu *QMenuBarPrivate::getPlatformMenu(QAction *action) { if (!action || !action->menu()) return 0; - return action->menu()->platformMenu(); + QPlatformMenu *platformMenu = action->menu()->platformMenu(); + if (!platformMenu && platformMenuBar) { + platformMenu = platformMenuBar->createMenu(); + if (platformMenu) + action->menu()->setPlatformMenu(platformMenu); + } + + return platformMenu; } /*! @@ -1236,14 +1243,14 @@ void QMenuBar::actionEvent(QActionEvent *e) return; if (e->type() == QEvent::ActionAdded) { - QPlatformMenu *menu = getPlatformMenu(e->action()); + QPlatformMenu *menu = d->getPlatformMenu(e->action()); if (menu) { QPlatformMenu* beforeMenu = NULL; for (int beforeIndex = d->indexOf(e->action()) + 1; !beforeMenu && (beforeIndex < actions().size()); ++beforeIndex) { - beforeMenu = getPlatformMenu(actions().at(beforeIndex)); + beforeMenu = d->getPlatformMenu(actions().at(beforeIndex)); } menu->setTag(reinterpret_cast<quintptr>(e->action())); @@ -1251,12 +1258,12 @@ void QMenuBar::actionEvent(QActionEvent *e) d->platformMenuBar->insertMenu(menu, beforeMenu); } } else if (e->type() == QEvent::ActionRemoved) { - QPlatformMenu *menu = getPlatformMenu(e->action()); + QPlatformMenu *menu = d->getPlatformMenu(e->action()); if (menu) d->platformMenuBar->removeMenu(menu); } else if (e->type() == QEvent::ActionChanged) { QPlatformMenu* cur = d->platformMenuBar->menuForTag(reinterpret_cast<quintptr>(e->action())); - QPlatformMenu *menu = getPlatformMenu(e->action()); + QPlatformMenu *menu = d->getPlatformMenu(e->action()); // the menu associated with the action can change, need to // remove and/or insert the new platform menu @@ -1271,7 +1278,7 @@ void QMenuBar::actionEvent(QActionEvent *e) !beforeMenu && (beforeIndex < actions().size()); ++beforeIndex) { - beforeMenu = getPlatformMenu(actions().at(beforeIndex)); + beforeMenu = d->getPlatformMenu(actions().at(beforeIndex)); } d->platformMenuBar->insertMenu(menu, beforeMenu); } diff --git a/src/widgets/widgets/qmenubar_p.h b/src/widgets/widgets/qmenubar_p.h index 04f608d22f..05b1878c20 100644 --- a/src/widgets/widgets/qmenubar_p.h +++ b/src/widgets/widgets/qmenubar_p.h @@ -143,6 +143,7 @@ public: QBasicTimer autoReleaseTimer; QPlatformMenuBar *platformMenuBar; + QPlatformMenu *getPlatformMenu(QAction *action); inline int indexOf(QAction *act) const { return q_func()->actions().indexOf(act); } |