PDA

View Full Version : Get pressed keys (no modifiers) from QMouseEvent



mariposa
25th September 2010, 11:08
Hi,

I would like to find out if the user pressed a key on the keyboard when clicking a mouse button on a widget. Unfortunately, the QMouseEvent carries only the information about the KeyboardModifiers, but I want to find out whether a letter key is pressed, let's say P+Left click.

Does anyone know how to achieve this?

Many thanks in advance :)

tbscope
25th September 2010, 11:44
You can get the key press in the key press event.
And the mouse event in the mouse event.

To find out if a key press event is happening at the same time as a mouse event, create your code in such a way that you hold a boolean (example isKeyDown) and a char (the actual key). Set the boolean to true when a key is down (watch out for repeats and input in widgets). Set it to false on key up. Then in the mouse event check that value of the boolean and the char.

Thinking out of the box.