PDA

View Full Version : Problem with keyPressedEvent and keyReleasedEvent



hubbobubbo
1st June 2010, 12:49
I have inherited the keyPress and keyRelease like below and the functions are called. The problem is that they are called a ton of times. If I press one key and keep it pressed I keep getting loads of keyPressed and keyRelease events even though the key is still down. If I just click the button normally it is ok, one keyPressed and one keyReleased but when I keep the button down there are multiple events for both pressed and released.

I test this on Win32 and I have tried it both in QMainWindow and a QDialog with the same problem.

void myDialog::keyPressEvent( QKeyEvent * event )
{
qDebug("Detected key %d down", event->key());
lbl->setText(tr("Down"));
}

void myDialog::keyReleaseEvent( QKeyEvent * event )
{
qDebug("Detected key %d up", event->key());
lbl->setText(tr("UP"));
}

tbscope
1st June 2010, 12:51
This is normal behaviour.
What is your question?

hubbobubbo
1st June 2010, 13:04
I think I resolved the first problem, I was not aware of the auto repeat feature. Now I use event->isAutoRepeat() to filter the auto repeats.

This part of the problem seems to be solved, will post a follow up questions in a new thread.