PDA

View Full Version : Issiue with resizing a QGraphcisItem after rotation



Elder
30th July 2015, 12:12
Hello guys I am new to this forum and this is my first thread and now to my problem.

I can not resize correctly after rotation. It seems like the position of my item is shifted.
For example, if I place my item to the mouse position, the corner of my item is not under the mouse.
It is shifted a little bit. It seems like something went wrong with my translation.
I used the following code for rotation.



QTransform transform;
transform.translate(boundingRect().width()/2, boundingRect().height()/2);
transform.rotate(getRotationAngle(event));
transform.translate(-(boundingRect().width()/2), -(boundingRect().height()/2));
setTransform(transform);

anda_skoa
30th July 2015, 12:58
If you only rotate around the center, you could try setting the transform origin point to the center

Cheers,
_

Elder
30th July 2015, 13:20
Do you mean like that:



this->setTransformOriginPoint(boundingRect().width()/2 , boundingRect().height()/2);
this->setRotation(getRotationAngle(event));
this->setTransformOriginPoint(0 , 0);


Maybe I should explain how I resize. I resize my item through mouse move. User has to click on one of the four corners and then drag into a direction.

I tried this too, but it only works for top left and bottom right corner.