The first item in my main menu is called "Project":

Qt Code:
  1. m_projectMenu = new QMenu("Pro&ject", m_menuBar);
To copy to clipboard, switch view to plain text mode 

So the user can hit "Alt+J" to open the menu via keyboard shortcut. Great!

For historical reasons, I'd also like the keyboard shortcut "Alt+F" to open the menu. I thought I could use a QShortcut, and hook it up to the menu's action:

Qt Code:
  1. QShortcut* fileshortcut = new QShortcut(QKeySequence("Alt+F"), m_projectMenu);
  2. QObject::connect(fileshortcut, SIGNAL(activated()),
  3. m_projectMenu->menuAction(), SLOT(trigger()));
To copy to clipboard, switch view to plain text mode 

But then pressing "Alt+F" only acts as if the mouse is hovering over the menu, rather than clicking to display the menu.

Then I thought of adding multiple keyboard shortcuts to the menu:

Qt Code:
  1. QList<QKeySequence> shortcuts;
  2. shortcuts.push_back(QKeySequence("Alt+F"));
  3. shortcuts.push_back(QKeySequence("Alt+J"));
  4.  
  5. m_projectMenu->menuAction()->setShortcuts(shortcuts);
To copy to clipboard, switch view to plain text mode 

But that doesn't work either. "Alt+F" does nothing, and "Alt+J" results in messages in stdout/stderr:

QAction::eventFilter: Ambiguous shortcut overload: Alt+J

So what's the correct way to do this? It seems that menuAction() does not return what I thought it returned, but the docs only say "Returns the action associated with this menu." Is that not the action on which keyboard shortcuts should be installed?