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
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
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.