Painting

Painting images in its basic form is as simple as calling drawImage() or drawPixmap() from the QPainter API. There are different variants of the two methods, but, basically, all of them allow one to specify which portion of a given image or pixmap is to be drawn and where. It is worth noting that painting pixmaps is preferred to painting images, as an image has to first be converted into a pixmap before it can be drawn.

If you have a lot of pixmaps to draw, a class called QPixmapCache may come in handy. It provides an application-wide cache for pixmaps. Using it, you can speed up pixmap loading while introducing a cap on memory usage.

Finally, if you just want to show a pixmap as a separate widget, you can use QLabel. This widget ...

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.