I play with graphics, and I implemented a simple camera movement using the arrow keys. My first approach was to override keyPressEvent to do something like this:
switch(key) { case up: MoveCameraForward(step); break; case left: MoveCameraLeft(step); break; ... }
This does not work as I would like. When I press and hold, for example, the “forward” button, the camera moves forward with “stepped” units, then stops for a while, and then continues to move. I assume that an event is generated this way to avoid multiple events in the case of a slightly long keystroke.
So, I need to poll the keyboard in my Paint() routine. I have not found how to do this with Qt. I was thinking about having a map<Key, bool> that would be updated in keyPressEvent and keyReleaseEvent and poll this map in Paint() . Any better ideas? Thanks for any ideas.
c ++ event-handling qt keyboard-events
Armen Tsirunyan
source share