What just happened?

When the view needs to display the scene, it calls the paint() function of each visible item and provides three arguments: a QPainter pointer that should be used for painting, a QStyleOptionGraphicsItem pointer that contains painting-related parameters for this item, and an optional QWidget pointer that may point to the currently painted widget. In the implementation of the function, we start with setting a cosmetic pen in the painter so that the line width of our graph is always 1. Next, we calculate the number of points in the graph and save it to the steps variable. Then, we create a variable to store the previous point of the graph and initialize it with the position of the first point of the graph (corresponding to ...

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.