Where is the origin for QGraphicsPixmapItem in its own system?
-
The question is asked for QGraphicsPixmapItem, but as I understand it, it is suitable for all classes that inherit QGraphicsItem. I know that the origin is in (0, 0) of the QGraphicsPixmapItem's coordinate system. I read about Item Coordinates. I did the following tests that led to this question.
- Adding a square's image from a file, no conversion
QGraphicsPixmapItem* i = scene.addPixmap(QPixmap(s));
Result:
- Adding a square's image from a file, 45 degree rotation
QGraphicsPixmapItem* i = scene.addPixmap(QPixmap(s)); i->setRotation(45);
Result:
It is not visible here, but when the program was started, the square rotated about its center on QGraphicsView.- Adding two images of a square, rotation of the second square by 45 degrees
QGraphicsPixmapItem* i = scene.addPixmap(QPixmap(s)); QGraphicsPixmapItem* i1 = scene.addPixmap(QPixmap(s)); i1->setRotation(45);
Result:
Here you can see that the first square is shifted to the right, the second square is turned relative to its upper left vertex.- Adding two images of a square, rotation of the first square by -45 degrees, rotation of the second square by 45 degrees
QGraphicsPixmapItem* i = scene.addPixmap(QPixmap(s)); QGraphicsPixmapItem* i1 = scene.addPixmap(QPixmap(s)); i->setRotation(-45); i1->setRotation(45);
Result:
Here you can see that the first square also is turned relative to its upper left vertex.The question is: where is the origin of the QGraphicsItem's system relative to the rectangle which bounds this item? Personally, I thought that (0, 0) is in the center of this rectangle. Why in the 2nd case the square turned around its center, and in the 3rd and 4th cases relative to its upper left vertex?
I know how to put the origin of a QGraphicsItem's coordinate system at a given point (to the center in this sample):i->setTransformOriginPoint(i->boundingRect().center());
I don't understand the default behavior. To make correct transformation should I set the origin for QGraphicsItem's system when I creating it?