PDA

View Full Version : how to set user defined shortcut keys in menu



gauravg
14th December 2011, 08:03
hi all please tell me how to set user defined shortcut keys in menu like(CTRL+ALT+P).




thanks with regards:
gauravg

QtMaci
14th December 2011, 19:49
Hi Gauravg,

the way I do it:

1. Create a QAction (QAction *action = new QAction(tr("New"))
2. Set the shortcut for the created QAction. (action->setShortcut("Ctrl+N"))
3. Add the QAction to your menu (menu->addAction(action))

Best regards

Ralf

Spitfire
15th December 2011, 11:16
Do you mean that it's the user that should be able to set the shortcuts to what he wants?

Oleg
15th December 2011, 11:31
If your want your app to give user possibility to set shortcuts, then implement shortcut editor inside your app and bind shortcuts to actions in runtime as in Ralf's sample.