PDA

View Full Version : How to prevent shortcut override events?



smacchia
20th December 2011, 23:36
I have an embedded app with multiple windows. It can be run on a regular laptop, which is where primary development is done.

The embedded device has a controller where some buttons act as keyboard events (press/release). When I interpret the mapping in the parent window (via ::event()) on the laptop (with a regular keyboard), everything works fine. But on the embedded device, all ::event ever receives is a ShortcutOverride event, never any key press or release events.

I tried an event filter on all child windows with the same result. Does anyone have any idea how I can just receive normal events?

smacchia
21st December 2011, 22:18
Just to reply with a solution I came up with, in case anyone is interested.

I ended up using an event handler in the child window base class which passes the event to the parent for processing. Then if the parent window doesn't process it, the event handler calls it's immediate base class event handler.

This seems to work. But I still want to understand why the parent window ::event only gets shortcut override. The documentation on that event is limited at best and it's unclear to me how it would be used and how to turn it off (or on) should that be desired.

smacchia
27th December 2011, 17:32
It turned out that even the event handler in the child didn't cause KeyPress or KeyRelease events to be sent to the child (or the parent). Only ShortcutOverride events were sent. The solution is to have the QWidget instance that needs to receive the events to call ::grabKeyboard. In my case, it's the parent window that exists for the life of the application. If you call this in child windows whose lifetimes are shorter, ::releaseKeyboard will need to be called too.

Hope this helps anyone who encounters a similar problem.

amleto
27th December 2011, 20:26
thanks for the update :)