I want implement a QDialog
, in which a key is pressed for some time (seconds) and is released afterwards.
I tried doing this with keyPressEvent
and keyReleaseEvent
functions.
The problem I get is that when a key is pressed the debounce (keyReleaseEvent
) occurs very quickly, which is not desired in my case.
Here, is what I do:
def keyPressEvent(self, eventQKeyEvent):
key = eventQKeyEvent.key()
if key == 54:
print('pressed') # 6
def keyReleaseEvent(self, eventQKeyEvent):
key = eventQKeyEvent.key()
if key == 54:
print('released') # 6
Output:
'pressed'
'released'
'pressed'
'released'
'pressed'
'released'
...
'pressed'
'released'
I would like to get either:
'pressed'
'released'
or:
'pressed'
'pressed'
'pressed'
...
'pressed'
'pressed'
'released'
You need to use isAutoRepeat: