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
并且每个事件类型 QEvent\QPaintEvent\QHoverEvent\etc 都会出现无尽的错误:
line NN, in eventFilter:
TypeError: QObject.eventFilter(QObject, QEvent): argument 2 has unexpected type 'QPaintEvent'
我怎样才能摆脱它?
提前致谢,
塞尔日
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
eventFilter()
不是类方法,因此您还需要传递self
:eventFilter()
is not a class method, so you need to passself
as well: