Control buttons with keyboard keys
I made a small app that sends commands to a robot like forward, backward etc. I have four buttons and their clicked(); slot does what I want them to do but now I would like to use the keyboard up down left right to essentially push those buttons. What do I have to do to get the input from the keyboard to activate the slots?
Re: Control buttons with keyboard keys
If this is a QWidget app, add something like the following to your class declaration:
Then something like this to the implementation of keyPressEvent:
Code:
switch(event->key()){
case Qt::Key_Up:
do stuff for the up arrow
break;
case Qt::Key_Left:
do stuff for the left arrow.
break;
case Qt::Key_Right:
do stuff for the right arrow.
break;
case Qt::Key_Down:
do stuff for the down arrow.
break;
case Qt::Key_0:
break;
}
Karl
Re: Control buttons with keyboard keys
Thanks Karl, I got it working with the W A S D keys but I cant seem to get the arrow keys working, any ideas as to why? Im using a laptop with ubuntu 13.04. I believe the focus has got something to do with it because I have a spin box in my app and when I hit the down key enough times it gets highlighted.
Re: Control buttons with keyboard keys