QT Detecting if the return keyis pressed and released or if it is long pressed

134 Views Asked by At

I am using QT on Windows 10.

I am using a QDialog where I want to push the QPushButtons also with the return key. However, I want that the user has to push the return key and release it again. Long pressing the return key should work only once and not several times.

I checked the keyPressEvent and the keyReleaseEvent, but unfortunately when I do a long press with the return key, I get continuously keyReleaseEvent and keyPressEvent.

Any ideas, how I can detect if the return key is long pressed or how I can I disable the long pressed functionality?

1

There are 1 best solutions below

1
Vahagn Avagyan On

you can start the timer in keyPressEvent and in keyReleaseEvent read elapsed

QElapsedTimer mTimer;
keyPressEvent ()
{
  .....
  mTimer.start();
  .....
}
keyReleaseEvent ()
{
  .....
  int mMilliseconds = mTimer.elapsed();
  .....
}

and you can set the label for a long press