tags:

views:

61

answers:

1
+1  Q: 

PyQt. TypeError

Hi everyone,

I set filter on my QMainWindow with this:

keyPressFilter = keypressfilter.KeyPressFilter(self)
self.installEventFilter(keyPressFilter)

KeyPressFilter itself:

class KeyPressFilter(QObject):

    def __init__(self, parent=None):
        super(KeyPressFilter, self).__init__(parent)


    def eventFilter(self, obj, event):
        if event.type() == QEvent.KeyPress:
            print "key press %d" % event.key()
            return True
        else:
            return QObject.eventFilter(obj, event)  <- line NN

and i getting endless errors with every eventtype QEvent\QPaintEvent\QHoverEvent\etc:

line NN, in eventFilter:
TypeError: QObject.eventFilter(QObject, QEvent): argument 2 has unexpected type 'QPaintEvent'

How can i get rid of it?

Thx in advance,

Serge

+2  A: 

eventFilter() is not a class method, so you need to pass self as well:

return QObject.eventFilter(self, obj, event)
Lukáš Lalinský