What just happened?

When an event occurs, Qt calls the corresponding virtual function in the widget in which the event occurred. In our case, whenever the user uses the mouse wheel on our view, the wheelEvent() virtual function will be called, and the event argument will hold information about the event.

In our implementation, we start with calling the base class's implementation. It is very important to do this whenever you reimplement a virtual function, unless you want the default behavior to be completely disabled. In our case, QGraphicsView::wheelEvent() will pass the event to the scene, and if we forget to call this function, neither the scene nor any of its items will receive any wheel events, which can be very much unwanted in some ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.