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:
void PlotWindow
::keyPressEvent( QKeyEvent *evnt
) {
switch( evnt->key( ) )
{
case Qt::Key_Control:
evnt->accept( );
mpFirstPlot->setControlKeyPressed( true );
break;
case Qt::Key_Up:
evnt->accept( );
fprintf( stderr, "up pressed\n" );
break;
case Qt::Key_Down:
evnt->accept( );
fprintf( stderr, "down pressed\n" );
break;
default:
evnt->ignore( );
}
}
void PlotWindow::keyPressEvent( QKeyEvent *evnt )
{
switch( evnt->key( ) )
{
case Qt::Key_Control:
evnt->accept( );
mpFirstPlot->setControlKeyPressed( true );
break;
case Qt::Key_Up:
evnt->accept( );
fprintf( stderr, "up pressed\n" );
break;
case Qt::Key_Down:
evnt->accept( );
fprintf( stderr, "down pressed\n" );
break;
default:
evnt->ignore( );
}
}
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!
Bookmarks