I have created a GUI using Qt Creator. That is by drag and drop the widgets. Now I want to assign shortcut keys a the button. Can anyone here please let me know how to do that? Thank you in advance
Hi, you can do it in the Creator by editing the property "shortcut" of the pushButton (e.g. press Ctrl and C in that property field)
You can put an ampersand in the buttons text eg.
auto button = new QPushButton("Hit &me!", parent);
You can also do that in the designer's properties. It will assign Alt+m to that button (whatever letter after &).
A more general way is to create a QAction.
Connect button clicked() signal to the action's trigger() slot.
Set a "shortcut":http://qt-project.org/doc/qt-5/qaction.html#shortcut-prop.
Set global (or whatever you want) shortcut "context":http://qt-project.org/doc/qt-5/qaction.html#shortcutContext-prop.
Connect to the triggered() signal of the action and do your work there.
Hi Clochydd &Chris Kawa
thank you both it's work for me