I am trying to have a QMainWindow capture keyPressEvents Qt::Key_Up and Qt::Key_Down. Unfortunately in my keyPressEvent( ) function, the print statements I have for these 2 keys do not print. My main window contains about 12 push buttons, 2 sliders, and 2 QGLWidgets. Upon further observation I noticed my 2nd slider bar was moving with the up and down keys.

Is there a way to get my sliders and push buttons from accpeting the key presses so my main window can receive them? My keyPressEvent looks like this:


Qt Code:
  1. void PlotWindow::keyPressEvent( QKeyEvent *evnt )
  2. {
  3. switch( evnt->key( ) )
  4. {
  5. case Qt::Key_Control:
  6. evnt->accept( );
  7. mpFirstPlot->setControlKeyPressed( true );
  8. break;
  9. case Qt::Key_Up:
  10. evnt->accept( );
  11. fprintf( stderr, "up pressed\n" );
  12. break;
  13. case Qt::Key_Down:
  14. evnt->accept( );
  15. fprintf( stderr, "down pressed\n" );
  16. break;
  17. default:
  18. evnt->ignore( );
  19. }
  20. }
To copy to clipboard, switch view to plain text mode 

Capturing the Control key works fine but I do not get anything to capture the up and down keys. Thanks for your help!