Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt: how to apply a 2-step key shortcut to action

I know how to apply a keyboard shortcut to an action. And in some software such as Visual Studio there are shortcuts that do the job in more than one step (such as Ctrl+K,Ctrl+C to comment the code).

Another example of that in Sublime Text:

I wonder whether or not it is possible to implement in Qt.

like image 276
Wuyue Lu Avatar asked Oct 30 '22 04:10

Wuyue Lu


1 Answers

You can create it by using the multiple arguments constructor for QKeySequence.

like this:

auto ac = new QAction(this);
ac->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_K, Qt::CTRL + Qt::Key_C));
like image 141
Devopia Avatar answered Nov 15 '22 06:11

Devopia