The theory of moving an object back to its beginning, rotation, and then replacing the position of the object is correct. However, the code you presented is not a translation and rotation of the object in general, but a translation and rotation of the painter. In the example you have indicated, they want to rotate the whole image around the object, so they move the artist to the center of the object before rotation.
The easiest way to rotate around a GraphicsItem is to first define an element centered in the center of the object, and not in the upper left corner. Thus, any rotation will automatically touch the center of the objects, without the need to translate the object.
To do this, you must define an element with a bounding box for x, y, width, height with (-width / 2, -height / 2, width, height).
Alternatively, if your object inherits from QGraphicsItem or QGraphicsObject, you can use the setTransformOriginPoint function before any rotation.
source share