title: How to detect global key sequence press in Qt?
body: <p>I want to detect whether a key sequence is pressed and want to perform certain task on that event in Qt. Currently I can detect keypresses for certain widgets but how to detect global keypresses. By global I mean that even if the application is minimized or hidden , it should detect key press.</p>
  
  <p>I tried making an <code>eventFilter</code> for the application, by first overloading <code>QObject::eventFilter</code> like this:</p>
  
  <pre><code>bool GlobalEventFilter::eventFilter(QObject *Object, QEvent *Event)
  {
    if (Event-&gt;type() == QEvent::KeyPress)
    {
      QKeyEvent *KeyEvent = (QKeyEvent*)Event;
  
      switch(KeyEvent-&gt;key())
      {
        case Qt::Key_F1:
          cout&lt;&lt;"F1 press detected"&lt;&lt;endl;
          return true;
        default:
          break;
      }
    }
    return QObject::eventFilter(Object,Event);
  }
  </code></pre>
  
  <p>and then installing that object as the <code>eventFilter</code> for my application:</p>
  
  <pre><code>QApplication a(argc,argv);
  a.installEventFilter(new GlobalEventFilter());
  </code></pre>
  
  <p>and I also tried the doing this:</p>
  
  <pre><code>QCoreApplication::instance()-&gt;installEventFilter(new GlobalEventFilter());
  </code></pre>
  
  <p>In both the cases I am able to detect key presses when my application window is open but it fails when window is minimized or hidden. How to solve this?</p>