Skip to content Skip to sidebar Skip to footer

Python PyQt5 - QEvent Keypress Executes Double Times

I have this simple code, when ESC key pressed PRINTS, however it seems executing 'double' times instead of firing one-time only. Python 3.6.2 x86 + PyQt 5.9 #!/usr/bin/env python3

Solution 1:

An event-filter installed on the QApplication will receive events for all objects in the application. So you need to check the obj argument to filter out events from objects you are not interested in.

In your example, you probably only want events from your main window. So you can fix it like this:

def eventFilter(self, obj, event):
    if (event.type() == QtCore.QEvent.KeyPress and obj is self):
        ...

Post a Comment for "Python PyQt5 - QEvent Keypress Executes Double Times"