PyQt的。类型错误

时间:2010-02-16 22:19:41

标签: pyqt

我用QMainWindow设置过滤器:

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

KeyPressFilter本身:

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

我在每个eventtype QEvent \ QPaintEvent \ QHoverEvent \ etc中遇到无穷无尽的错误:

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

我怎样摆脱它?

提前,

塞尔

1 个答案:

答案 0 :(得分:6)

eventFilter()不是类方法,因此您还需要传递self

return QObject.eventFilter(self, obj, event)