OS X + Qt: How to capture all key-press events in the entire GUI?
macos, pyside, python, qt
Solution
When an event is used by a widget (e.g. an edit box), it is usually not propagated to its parent widgets, so you can't get these events from the parent window. You should install an event filter on the main `QApplication` object. This way you will receive (and filter if you want) all events.
See Event filters.
Problem
I have a basic question about Qt and Mac OS X. If I define a `QMainWindow` class and define a `keyPressEvent` function as below, is it not supposed to enter this function whenever a key is pressed anywhere in the `MyWindow`? I have some problems with it under Linux, where I do not get the keypress events if certain widgets were focused on (list views or edit boxes), but at least I get it if I focus on a button and then press a key. Under Mac OS X I do not get any response at all. ``` class MyWindow(QMainWindow): def keyPressEvent(self, event): key = event.key() if key == Qt.Key_F: print("pressed F key") ``` Any ideas (using Python with PySide)?