[Qt-interest] How to catch key press/release first?

Martin Gebert martin.gebert at alpha-bit.de
Fri May 15 12:58:42 CEST 2009


Hi!

I'm currently exploring possibilities to catch key press and release events for the cursor keys and handle them before any other widget gets the chance. For context: my app/dialog needs a special "move around" mode where cursor keys are for movement of some target only (down -> start, up -> stop), and if that mode is off they should be handled as usual, depending on the widget that has the focus. 
I tried QWidget::grabShortcut(), but that doesn't give me a distinction of key down/up. event() and keyPressEvent() are called too late, after the currently focused widget got its turn. Next I'm thinking about registering an event filter in the QAppliction object. Any tips how to implement this behaviour reliably, respectively where to override the default behaviour?
Thanks!

Martin







More information about the Qt-interest-old mailing list