PDA

View Full Version : KeyPressEvent behaves strange, skips the F key.



pir
12th August 2006, 01:34
Hi!

I have reimplemented the keyPressEvent to do some stuff. But I can't make it work. The purpose of the key events is to do something and then a GLWidget is supposed to be redrawn to show the result. It works with some keys, but nothing happens when sertain keys are pressed. Or at least nothing is done until I do something else that requires the GLWidget to be redrawn. When that is done, the result is shown.

Here is some code, the F key is the one not working. The A key works just fine, also the Shift and all the rest. Maybe I haven't called setFocusPolicy ( ) correct. I've tried to insert it in the mousPressEvent(), but that didn't do anything.

I tried to print some trace text, but that didn't come out as I hoped. Look in the code...



void keyPressEvent ( QKeyEvent *event )
{
std::cout<<"this is not always written when a key is pressed..."<<std::endl;
switch ( event->key() )
{
case Qt::Key_Shift:
{
// WORKS FINE
}
break;

case Qt::Key_A:
{
// WORKS FINE
// does something ....
update ( ); // updates the GLWidget
}
break;

case Qt::Key_F:
{
// THIS KEY DOESN'T WORK!
focusSelection ( );
update ( );
}
break;

default:
event->ignore ( );

}// switch

}// keyPressEvent(QKeyEvent*)


thanks for reading
pir

wysota
18th August 2006, 18:07
What does focusSelection() do? Could you make a minimal compilable example which reproduces the problem?