0

I tried to set an action in a QMenu with the ampersand shortcut (&) but the shortcut is not rendered. I should have a rendering like the "Help" action with the F11 shortcut.

Window screenshot

The code:

QMenu* filesMenu = ui->menubar->addMenu("&Test");
QAction* ampersandAction = filesMenu->addAction("Ampersand!");
ampersandAction->setShortcut(Qt::Key_Ampersand);
Theo
  • 13
  • 5

1 Answers1

0

Your code is fine and working. Just press the "Alt" touch while your app is running and your letter will be underlined as you want it to be.

Issylin
  • 353
  • 2
  • 3
  • 11
  • My goal is to show the ampersand shortcut in the menu like the "Help" action with the F11 shortcut. I have edited my post. – Theo Jun 27 '22 at 07:03
  • @Theo it seems the ampersand character is used by QKeySequence as a pattern matcher, which is one of the class behind the scenes for setting shortcuts. You should pick another character than '&' for a shortcut. – Issylin Jun 27 '22 at 22:31
  • Far too good to give up that idea :'(, thanks for the help! – Theo Jun 30 '22 at 07:44