PDA

View Full Version : mouse move event filtering in PyQt4



lucaf
4th April 2009, 10:15
Hi,
I need to filter mouse moving on a QGraphicsView in PyQt4. I created a filter and install it to a QGraphicsView instance, but desired event seems not to be captured.

Following a simple example showing how no mouse moving is filtered by eventFilter() function:


import sys

from PyQt4 import QtCore, QtGui

class Filter(QtCore.QObject):
def eventFilter(self, obj, event):
print event.type()
return False

class MainWin(QtGui.QMainWindow):

def __init__(self, parent=None, flags=QtCore.Qt.Widget):
QtGui.QMainWindow.__init__(self, parent, flags)

self.scene = QtGui.QGraphicsScene(self)
self.graphicsview = QtGui.QGraphicsView(self.scene, self)
self.graphicsview.setMouseTracking(True)
self.filter = Filter(self.graphicsview)
self.graphicsview.installEventFilter(self.filter)
self.setCentralWidget(self.graphicsview)

def main():
app = QtGui.QApplication(sys.argv)
mainwin = MainWin()
mainwin.show()
sys.exit(app.exec_())

if __name__ == '__main__':
main()

Thanks to all ones that answer after reading this very complex code

lucaf
4th April 2009, 15:53
Can someone help me? :crying: