I have a custom QGraphicsScene with a custom item on it. Both scene and item have wheelEvent(self,event) handlers, but only the scene handler gets called. The documentation claims items under the cursor get the event first, and it only goes to the scene if they all ignore it. That's not what seems to be happening.

If I remove the scene's eventWheel handler then the item gets wheel events.

Here's some PyQt4 code that shows it. As it is, only the scene gets wheel events. Comment out MyScene's wheelEvent handler and then MyItem gets them. Same for everyone else? This is on Ubuntu Hardy.

Qt Code:
  1. from PyQt4.QtCore import *
  2. from PyQt4.QtGui import *
  3.  
  4. class MyItem(QGraphicsRectItem):
  5. def __init__(self,x,y,w,h,parent):
  6. QGraphicsRectItem.__init__(self,w/2.0,h/2.0,w,h,parent)
  7. self.setPos(x,y)
  8. self.setPen(QPen(Qt.NoPen))
  9. self.setBrush(QBrush(QColor(Qt.black)))
  10. def wheelEvent(self,event):
  11. print "Item got a wheel"
  12.  
  13. class MyScene(QGraphicsScene):
  14. def __init__(self):
  15. QGraphicsScene.__init__(self)
  16. def wheelEvent(self,event):
  17. print "scene got a wheel"
  18.  
  19. app = QApplication([])
  20.  
  21. dialog = QDialog()
  22. view = QGraphicsView()
  23. scene = MyScene()
  24.  
  25. layout = QVBoxLayout()
  26. layout.addWidget(view)
  27. dialog.setLayout(layout);
  28. m1 = MyItem(0,0,100,100,None)
  29. scene.addItem(m1)
  30. view.setScene(scene)
  31.  
  32. dialog.show()
  33.  
  34. app.exec_()
To copy to clipboard, switch view to plain text mode