How to Program custom Keyboard Shortcuts

后端 未结 4 1069
北荒
北荒 2020-12-24 13:19

I have a Qt application on Linux.

I\'d like to program custom keyboard shortcuts such as CTRL-Q which will then call a subroutine which quits

4条回答
  •  甜味超标
    2020-12-24 14:04

    this is a sample to create file menu and exit action and connection between signal and slot.

    QMenu *fileMenu = new QMenu(trUtf8("&File"));
    QAction *actionExit = new QAction(tr("E&xit"));    
    //set "ctrl+q shortcut for exit action
    actionExit->setShortcut(tr("CTRL+Q"));
    //connect triggered signal of actionExit to close slot
    connect(actionExit, SIGNAL(triggered()), this, SLOT(close()));
    //add actionExit into file menu
    fileMenu->addAction(actionExit);
    

提交回复
热议问题