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
def eventFilter(self, obj, event):
print event.type()
return False
def __init__(self, parent=None, flags=QtCore.Qt.Widget):
self.graphicsview.setMouseTracking(True)
self.filter = Filter(self.graphicsview)
self.graphicsview.installEventFilter(self.filter)
self.setCentralWidget(self.graphicsview)
def main():
mainwin = MainWin()
mainwin.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
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()
To copy to clipboard, switch view to plain text mode
Thanks to all ones that answer after reading this very complex code
Bookmarks