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:
{
if (_view->underMouse())
{
if (event->delta() > 0)
_view->scale(2, 2);
else if (event->delta() < 0)
_view->scale(0.5, 0.5);
}
}
void MyFrame::wheelEvent(QWheelEvent* event)
{
if (_view->underMouse())
{
if (event->delta() > 0)
_view->scale(2, 2);
else if (event->delta() < 0)
_view->scale(0.5, 0.5);
}
}
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.
Bookmarks