[PyQt] Catching key events

Frédéric frederic.mantegazza at gbiloba.org
Sat Jan 17 16:57:01 GMT 2009


On vendredi 16 janvier 2009, Frédéric wrote:

> 1) catching key events
>
> I found that I have to implement the keyPressEvent() method. I did this
> in the mainWindow, but the behaviour depend where is the focus. And as I
> want to catch arrow keys, it also change the focus! What is the proper
> way to do this? I also want to rebind key TAB, to avoid changing the
> focus, space, and enter...

Ok, I solved most of my problems using grabKeyboard()/releaseKeyboard() 
methods.

I still have an issue: when I hold down a key, once the repeat starts, I 
receive both KeyPressed and KeyReleased events. This is a different 
behaviour as PyGTK, where I only received the key-pressed-event while 
holding it down, and the key-release-event when I release the key.

Is there a way to do this in PyQt? I want to start the motor head when I 
press the key, and stop it when I release the key. Now, it does not work, 
as the motor is started/stopped too quickly (which is not very good)...

-- 
    Frédéric

    http://www.gbiloba.org



More information about the PyQt mailing list