O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required