Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I assign a shortcut to a QPushButton?

The documentation on assigning a shortcut to a QPushButton is as follows:


A shortcut key can be specified by preceding the preferred character with an ampersand in the text. For example:

QPushButton *button = new QPushButton("&Download", this);

In this example the shortcut is Alt+D.


What do I do if I don't want an Alt+[A-Z] shortcut? For example, in my case I want my button to be fired when the TAB button is pressed. How can I achieve this effect?

like image 860
Kvass Avatar asked Sep 22 '14 15:09

Kvass


1 Answers

You can use setShortcut method, eg:

pushButton->setShortcut(QKeySequence(Qt::Key_Tab));

It will fire then slots assigned to the clicked() signal

like image 152
Rafal Mielniczuk Avatar answered Oct 08 '22 11:10

Rafal Mielniczuk