Game Programming using Qt 5 Beginner's Guide - Second Edition
by Pavel Strakhov, Witold Wysota, Lorenz Haas
What just happened?
First, you determined the rectangle of the scene with sceneRect(). Since this returns a QRectF parameter and QImage can only handle QRect, you transformed it on the fly by calling toAlignedRect(). The difference between the toRect() function and toAlignedRect() is that the former rounds to the nearest integer, which may result in a smaller rectangle, whereas the latter expands to the smallest possible rectangle containing the original QRectF parameter.
Then, you created a QImage file with the size of the aligned scene's rectangle. As the image is created with uninitialized data, you need to call fill() with Qt::transparent to receive a transparent background. You can assign any color you like as an argument both as a value ...
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