Resize a rotated GraphicsItem from Center

122 Views Asked by At

https://forum.qt.io/topic/67664/solved-resizable-rotatable-graphicsitem

Hello, the above post resizes with the handle selected and changes the center of the boundingRect. I need to do the same by keyPressEvent and it would resize the rotated boundingRect uniformly from center, ie, it'll increase the width by 1 unit on both right and left sides, similarly decrease by 1 unit on both sides and similarly increase/decrease the height. Now the problem with keyPress is that we'll not get

QPointF ptMouseMoveInItemsCoord = mapFromScene(event->scenePos()); //in mouseMoveEvent

so we know where to set the edges of the boundingRect, but we don't have this when we increment/decrement the width/height on both sides uniformly without changing the center.

How can we find the new scenecoords of the boundingRect, known old sceneCoords, angle, width and height of boundingRect, center should remain same?

1

There are 1 best solutions below

2
On

do you mean to increase the bounding rect by 1 on each side in item coordinates (= the rotated coordinate system)?

If so, it should be as easy as to calculate the new bounding box in item coordinates:

adjustedRect = boundingRect().adjusted(-1,-1, 1, 1);

and then map it back to scene coordinates:

QPolygonF poly = mapToScene(adjustedRect);

The polygon will contain a list of points with the bounding rect coordinates relative to the scene coordinate system.