PDA

View Full Version : F2 keyPressEvent Not Capturing



Rayven
30th July 2007, 19:31
In my main application window (QMainWindow), I am capturing the keyPressEvent for all the Function keys. I am successfully capturing F1, F3-F12, but F2 will not cause a keyPressEvent. I have looked throughout my main window code and I am not using F2 for any other shortcut that I know of. The thing that really has me puzzled is that I am creating a second QMainWindow and capturing the F1-F12 keyPressEvents without any problem. Is there some default shortcut that uses F2 that I am missing? I have ensured that I am using accept( )/ignore( ) throughout the press event.



void MainWindow::keyPressEvent( QKeyEvent *event )
{
//This line will print for every key other than F2
fprintf( stderr, "In MainWindow::keyPressEvent( QKeyEvent *event )" );

QString keySequence = "";

if( event->state( ) & Qt::ControlButton )
{
keySequence += tr( "Ctrl+" );
}
if( event->state( ) & Qt::ShiftButton )
{
keySequence += tr( "Shift+" );
}
if( event->state( ) & Qt::AltButton )
{
keySequence += tr( "Alt+" );
}
if( event->state( ) & Qt::MetaButton )
{
keySequence += tr( "Meta+" );
}

if( event->key( ) != Qt::Key_Control &&
event->key( ) != Qt::Key_Shift &&
event->key( ) != Qt::Key_Meta &&
event->key( ) != Qt::Key_Alt )
{
... continue building the keySequence and check against configuration file
}

event->ignore( );

ToddAtWSU
2nd August 2007, 20:41
I think I have found the solution to your problem. If you follow this link http://trolltech.com/developer/notes/changes/changes-3.3.8/ you will see there was a problem with capturing F2 in QTables that they had some problems. Do you have a QTable in your main window? If so try subclassing the QTable and ignore the key press event at least for the F2 key so it goes up to your main window. Let me know if this helps and if it does not I will look for other ideas. :D