Mouseover event filter for PyQT tag

I am trying to convert an example here to work with a simple label.

Here is the code:

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) 

Now it’s curious that this really works, but not without my console being mousemove! (good) as well as an error: TypeError: invalid result type from mouseoverEvent.eventFilter ()

I still do not quite understand the complex relationship between the events, so this is a little Greek for me. So what gives?

Thanks in advance.

+4
source share
3 answers

I believe that you need to return True or False from eventFilter to indicate whether you have fully processed the event or not.

+7
source

Look what I just discovered. This is a snippet from some actual code, so the class names are specific to my instance.

  def mouseMoveEvent(self, event=None): if self.activeLayer.layerName != 'Whiteboard': super(MapPage, self).mouseMoveEvent(event) else: if (event.buttons() & Qt.LeftButton) and self.scribbling: self.drawLineTo(event.scenePos()) 

What I did was re-declared mouseMoveEvent, but if the executable instance of activeLayer is not called "Whiteboard", then the software runs through the "original" mouseMoveEvent.

0
source

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!" return super(mouseoverEvent, self).eventFilter(object, event) 

self.filter = mouseoverEvent (self) self.label.installEventFilter (self.filter)

0
source

All Articles