You are not logged in.

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.

1

Sunday, March 21st 2010, 6:39am

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?
Be free, feel freedom.
http://opentechlab.blospot.com

2

Sunday, March 21st 2010, 11:37am

may be like this

Source code

1
QPushButton *button = new QPushButton("&Download", this);// Alt+D

and try to read and use QShortcut

3

Monday, March 22nd 2010, 1:31pm

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.
Be free, feel freedom.
http://opentechlab.blospot.com

Junior

Professional

  • "Junior" is male

Posts: 1,613

Location: San Antonio, TX USA

Occupation: Senior Secure Systems Engineer

  • Send private message

4

Monday, March 22nd 2010, 2:16pm

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.

5

Monday, March 22nd 2010, 3:57pm

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?
Be free, feel freedom.
http://opentechlab.blospot.com

6

Tuesday, March 23rd 2010, 1:29pm

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?
Be free, feel freedom.
http://opentechlab.blospot.com

Junior

Professional

  • "Junior" is male

Posts: 1,613

Location: San Antonio, TX USA

Occupation: Senior Secure Systems Engineer

  • Send private message

7

Tuesday, March 23rd 2010, 2:05pm

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.