I work on a Qt application that is mainly developed on MacOS, but then it is also built and tested on Linux.
We define the keyPressEvent () method in our main window class to respond to certain keyboard events. In particular, we respond to Qt :: Key_Left, Qt :: Key_Right and Qt :: Key_Space. This works great on macOS. However, on Linux, we never get these events.
Performing some actions on Google (and confirming this with our Linux application behavior), it seems that the reason for this is because Qt uses these keys to navigate the keyboard of button widgets in the application’s GUI. If I press the arrow keys on Linux, I look at all the active button widgets, each time selecting them one by one. If I press the spacebar, the selected button is pressed.
All I have been able to find so far in Googling are suggestions on how to subclass or apply filters to certain buttons to avoid this behavior if the button ignores the event and passes it. But I do not want to do this for every button widget that I have ever added to my GUI. It is just lame.
Is there a way to disable this behavior globally and let my application code actually get ALL of the arrow keys and spaces?
Steve source share