I've created a form with Qt Creator, on which I have a QGraphicsView object.
I'd like to be able to zoom this item by intercepting the the wheelEvent function, but I don't want to have to subclass QGraphicsView and override wheelEvent there, so instead I overrode wheelEvent in the parent frame:

Qt Code:
  1. void MyFrame::wheelEvent(QWheelEvent* event)
  2. {
  3. if (_view->underMouse())
  4. {
  5. if (event->delta() > 0)
  6. _view->scale(2, 2);
  7. else if (event->delta() < 0)
  8. _view->scale(0.5, 0.5);
  9. }
  10. }
To copy to clipboard, switch view to plain text mode 

Where _view refers to my QGraphicsView object. This seems a bit clunky but it appears to work. Is there a better way of doing this?


Now the second question: although the above works, I notice that as soon as scroll bars appear in the QGraphicsView, then this functionality fails, and scrolling the mousewheel will instead cause the view to scroll. I presume this is because wheelEvent is being intercepted somewhere else, before my frame can handle it. Is there a way around this? I want the mousewheel to ALWAYS scroll the view.