How to use QShortcut



  • Hello,
    I tried using QShortcut for the first time:
    @QShortcut *shortcut = new QShortcut(Qt::Key_F2, this, SLOT(popmenuf());@

    popmenuf() is called but this is not exactly what I am trying to do. The parent should not be "this" but "tree", a child widget of "this". If I just replace the parameter, pressing F2 does not activate the slot anymore.



  • You normally put shortcuts in the top-level widget. Otherwise, they only work if the widget you put them on has input focus.



  • First create an Action (new Action()).
    Set the action's shortcut (yourAction->setShortcut(Qt::Key_F2)).
    Connect signal slot as your intent.
    Set the action to your widget: your(Tree?)Widget->addAction(yourAction).



  • It's a bit embarrasing, but it was just a typo in the slot.
    Sorry for the unnecessary question.


Log in to reply
 

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