How to set custom keysequence for QAction menu element



  • Hi,

    First of,m I'm a newbie!
    I have a menu bar with some actionm points to which I now want to assign a short cut. I've done this already for available shortcuts like quitAct->setShortcuts(QKeySequence::Quit); which worked fine but I now also want to add one with a customized shortcut of Ctrl+;, I'ver tried this: splitHAct->setShortcuts(QKeySequence(tr("Ctrl+;","Ctrl+;"))); but am only getting: error: no matching function for call to ‘QAction::setShortcuts(QKeySequence)’ how can I get my custom shortcut going?
    Thanks!



  • @cerr
    How you tried this ?


  • Moderators

    @cerr
    the QAction::setShorcuts() expects a list of QKeySequences. You want to use QAction::setShortcut() which expects a single QKeySequence parameter.
    Note that a single QKeySequence can actually hold up to 4 shortcuts.

    Also note that such shortcuts (using special characters) are problematic on some keyboard layouts. For example on a german layout to get ; i also have to press the SHIFT modifier.

    Edit: you may want to use QKeySequenceEdit widget to check the key sequence for your shortcut.



  • @raven-worx Yep, Thanks! That was it: QAction::setShortcut()


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.