title: OS X + Qt: How to capture all key-press events in the entire GUI?
body: <p>I have a basic question about Qt and Mac OS X. If I define a <code>QMainWindow</code> class and define a <code>keyPressEvent</code> function as below, is it not supposed to enter this function whenever a key is pressed anywhere in the <code>MyWindow</code>? 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. </p>
  
  <pre><code>class MyWindow(QMainWindow):    
      def keyPressEvent(self, event):
          key = event.key()
  
          if key == Qt.Key_F:
              print("pressed F key")
  </code></pre>
  
  <p>Any ideas? </p>
  
  <p>(using Python with PySide)</p>
  
  <p>[edit] solution based on Pavels answer:</p>
  
  <pre><code>import sys
  from PySide.QtGui import *
  from PySide.QtCore import * 
  
  
  class basicWindow(QMainWindow):  
  
      def __init__(self):
          QMainWindow.__init__(self)
  
          self.edit = QLineEdit("try to type F", self)
  
          self.eF = filterObj(self)
          self.installEventFilter(self.eF)
          self.edit.installEventFilter(self.eF)
          self.show()
  
      def test(self, obj):
          print "received event", obj
  
  class filterObj(QObject):
      def __init__(self, windowObj):
          QObject.__init__(self)
          self.windowObj = windowObj
  
      def eventFilter(self, obj, event):
          if (event.type() == QEvent.KeyPress):
              key = event.key()
  
  
              if(event.modifiers() == Qt.ControlModifier):
                  if(key == Qt.Key_S):
                      print('standard response')
  
              else:                    
                  if key == Qt.Key_F:
                      self.windowObj.test(obj)
  
              return True
          else:
              return False          
  
  
  if __name__ == "__main__":
      app = QApplication(sys.argv)
  
      w = basicWindow()
  
      sys.exit(app.exec_())
  </code></pre>