Dear visitor, welcome to QtForum.org.
If this is your first visit here, please read the Help. It explains in detail how this page works.
To use all features of this page, you should consider registering.
Please use the registration form, to register here or read more information about the registration process.
If you are already registered, please login here.
Assign keybaord shortcut for pushbutton click
Hai all,
I want to make a keyboard short cut to call a function instead of clicking a pushbutton. Can anyone help me?
may be like this
|
Source code
|
1
|
QPushButton *button = new QPushButton("&Download", this);// Alt+D
|
and try to read and use QShortcut
Reply
But I found there is no sign of indication of the shortcut as Alt+D in your program. What is &download? i am not much aware of Qt coding. If you don't mind, give a way to use shortcuts in Qtcreator designer. Is it possible to do in the property editor of pushButton? If there is no way to do it in GUI way, direct code is enough.
In designer, edit the text of the PushButton and add the Aphere sign in front of the character you which to use Alt key with.
Then to test, in designer do form preview and test the Alt key that you assigned the Pushbutton.
Success
Thank you very much.
In case I am not using any pushbutton and needs to execute a function with a keyboard shortcut. I mean there is no widgets connected to the function. But the function is executed when a keyboard shortcut is pressed. A dummy pushbutton is a good answer.But any better idea?
Please answer
Please answer my above(previous post) question first.
Secondly, In case I want not 'Alt+character' short cut and needs arrow keys as my shortcut to pushbutton, what do I do?
First question: Take a look at using an eventFilter for trapping keys:
lineeditexample
Also you can automate a pushbutton click like this:
pushButton->animateClick();
Also there have been recent posts about working with key events.