Game Programming using Qt 5 Beginner's Guide - Second Edition
by Pavel Strakhov, Witold Wysota, Lorenz Haas
What just happened?
In the preceding code, we created a basic boilerplate code for using a canvas. First, we created a Canvas instance with an implicit width and height set. There, we created a handler for the paint signal that is emitted whenever the canvas needs to be redrawn. The code placed there retrieves a context for the canvas, which can be thought of as an equivalent to the QPainter instance we used when drawing on Qt widgets. We inform the canvas that we want its 2D context, which gives us a way to draw in two dimensions. A 2D context is the only context currently present for the Canvas element, but you still have to identify it explicitly—similar to HTML. Having the context ready, we tell it to clear the whole area of the canvas. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access