I have created a GUI using Qt Creator. That is by drag and drop the widgets. Now I want to assign shortcut keys for all of the buttons. Can anyone here please let me know how to do that? Thank you in advance.
Right-click the control for which you want to set a keyboard shortcut, and then click Control Properties on the shortcut menu. Click the Advanced tab. In the Access key box, type a character. An access key is simply a keyboard shortcut that uses the ALT key as part of the shortcut.
To reassign a keyConnect the keyboard that you want to configure. Select the Start button, and then select Microsoft Mouse and Keyboard Center. From the displayed list of key names, select the key that you want to reassign. In the command list of the key that you want to reassign, select a command.
Your buttons probably have a slot connected to their clicked()
signal.
To add shortcut keys, you simply connect a shortcut key's activated()
signal to the same slot.
In your code, #include <QShortcut>
and then you will be able to add a shortcut key for a slot like this:
QShortcut *shortcut = new QShortcut(QKeySequence("Ctrl+O"), parent); QObject::connect(shortcut, SIGNAL(activated()), receiver, SLOT(yourSlotHere()));
Where parent is the parent of your shortcut (for example the main window), yourSlotHere()
is the name of the slot you want the shortcut to call, and receiver
the object where yourSlotHere()
is.
Replace "Ctrl+O"
with whatever shortcut you want to assign.
You can also find more information on the documentation page for QShortcut.
Alternatively, if the shortcut key corresponds to some character in the text of the button, you can preped & to that character. If you want a literal &, use &&.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With