title: Handling left and right key events in QT
body: <p>I have a <code>QTabWidget</code> in one of my QT windows, and it seems to be swallowing the left/right key press events. In the main window I have the following function:</p>
  
  <pre><code>void VisionWindow::keyPressEvent(QKeyEvent* event) {
      std::cout &lt;&lt; event-&gt;key() &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>When I press any key other than left or right, the handler goes off and prints the key code to the console. When I press left or right, it moves to the next left (or right) tab in the tab widget, and the <code>VisionWindow</code>'s <code>keyPressEvent</code> method never fires.</p>
  
  <p>I tried to fix this with a subclass that would ignore the event:</p>
  
  <pre><code>class KeylessTabWidget : public QTabWidget {
      public:
          KeylessTabWidget(QWidget* parent) : QTabWidget(parent) {}
          void keyPressEvent(QKeyEvent* event) { event-&gt;ignore(); std::cout &lt;&lt; "ignored an event\n"; }
  };
  </code></pre>
  
  <p>Similar to the main window, this is only called when keys other than left or right are pressed. I'm also seeing that based on where the focus is, sometimes hitting left or right will switch the focus to different widgets in the main window, like checkboxes. If there any way to reclaim the left and right keys, or should I just accept that these are widely used in QT by default and switch to something else?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I ended up using <code>#include &lt;QApplication&gt;</code> along with <code>qApp-&gt;installEventFilter(this);</code> in my window constructor. The downside is that the tab widget is still switching tabs. <a href="https://stackoverflow.com/questions/5987977/how-do-i-disable-qts-behavior-on-linux-of-capturing-arrow-keys-for-widget-focus">This seems to be a linux issue</a>.  On the plus side, I'm able to capture all key events. I was having events get swallowed by child widgets for other keys as well, and this solved it.</p>