Time for action – rotating an item

As an example, let's rotate itemB and itemC by 45 degrees counter-clockwise. For itemB, the function call would look like this:

itemB->setRotation(-45);

The setRotation() function accepts qreal as the argument value, so you can set very precise values. The function interprets the number as degrees for a clockwise rotation around the z coordinate. If you set a negative value, a counter-clockwise rotation is performed. Even if it does not make much sense, you can rotate an item by 450 degrees, which would result in a rotation of 90 degrees. Here is what the two items would look like after the rotation by 45 degrees counter-clockwise:

What just happened?

As you can see, the rotation has its center in the item's origin ...

Get Game Programming Using Qt 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.