PyQT标签的鼠标悬停事件过滤器 [英] Mouseover event filter for a PyQT Label
问题描述
我一直在尝试转换示例这里使用一个简单的标签.
I've been trying to convert the example here to work with a simple label.
代码如下:
class mouseoverEvent(QtCore.QObject):
def __init__(self, parent):
super(mouseoverEvent, self).__init__(parent)
def eventFilter(self, object, event):
if event.type() == QtCore.QEvent.MouseMove:
print "mousemove!"
self.filter = mouseoverEvent(self)
self.label.installEventFilter(self.filter)
现在奇怪的是,它确实有效,但是在我的控制台中没有"mousemove!"垃圾邮件的情况下(良好)以及错误: TypeError:mouseoverEvent.eventFilter()中无效的结果类型
Now curiously, this actually works, but not without my console being spammed with "mousemove!" (good) as well as the error: TypeError: invalid result type from mouseoverEvent.eventFilter()
我还没有弄清楚事件之间的复杂关系,所以这对我来说有点希腊.那么,有什么用呢?
I've not quite figured out the complex relationship between events yet, so this is a bit greek to me. So, what gives?
谢谢.
推荐答案
我相信您需要从eventFilter返回True
或False
,以表明您是否已完全处理事件.
I believe you need to return True
or False
from the eventFilter, to indicate whether you have handled the event completely or not.
这篇关于PyQT标签的鼠标悬停事件过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!