title: Qt Widget - how to capture just a few keyboard keys
body: <p>I know that with grabKeyboard() my widget is able to grab every keyboard event also if it's not focused, but what if I wanted to capture just three or four keys?</p>
  <p>I tried with an event filter
  <a href="https://doc.qt.io/qt-5/qobject.html#installEventFilter" rel="nofollow noreferrer">https://doc.qt.io/qt-5/qobject.html#installEventFilter</a></p>
  <p>but that didn't work (perhaps because I installed it like this?)</p>
  <pre><code> class MyWidget: public QGLWidget
      {
          ...
      protected:
          bool eventFilter( QObject *o, QEvent *e );
      };
  
      bool MyWidget::eventFilter( QObject *o, QEvent *e )
      {
          if ( e-&gt;type() == QEvent::KeyPress ) {
              // special processing for key press
              QKeyEvent *k = (QKeyEvent *)e;
              qDebug( &quot;Ate key press %d&quot;, k-&gt;key() );
              return TRUE; // eat event
          } else {
              // standard event processing
              return FALSE;
          }
      }
  
  // Installed it in the constructor
  MyWidget::MyWidget()
  {
      this-&gt;installEventFilter(this);
  }
  </code></pre>
  <p>How can I intercept just a few keys in my widget and leave other widgets (QTextEdits) the rest?</p>