January 2016
Beginner
512 pages
12h 35m
English
Let's do the scaling first. We add the item to a scene and put that scene on a custom view we have subclassed from QGraphicsView. In our customized view, we only need to reimplement wheelEvent() as we want to scale the view by using the mouse's scroll wheel.
void MyView::wheelEvent(QWheelEvent *event) {
const qreal factor = 1.1;
if (event->angleDelta().y() > 0)
scale(factor, factor);
else
scale(1/factor, 1/factor);
}The factor parameter for the zooming can be freely defined. You can also create a getter and setter method for it. For us, 1.1 will do the work. With event->angleDelta(), you get the distance of the mouse's wheel rotation as a QPoint pointer. Since we ...