0

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?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Sayan Bera
  • 135
  • 2
  • 16
  • The link has the code – Sayan Bera Jan 06 '20 at 16:40
  • It seems you haven't read the link. I explain to you, MRE is an important part of your question, so that should not depend on an external resource as an external link because if the link is broken your question will be useful for future readers. So my recommendation is that you edit your question and add it there. You have been in the site where you have asked 18 questions for more than 2 years, so you should already know this rule. – eyllanesc Jan 06 '20 at 16:43
  • OK...I'll read the rules and get back – Sayan Bera Jan 07 '20 at 04:45

1 Answers1

0

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.

Roman Schaub
  • 126
  • 1
  • 8
  • actually bounding rect remains at 0deg, even after rotating the box, so maybe adjusted() will not work...although I'll give a try – Sayan Bera Jan 17 '20 at 11:47
  • yes, the bounding rect is always expressed in item coordinates. adjusted() in this case will change its size along the axis of the rotated item, not along the 'scene' axis. mapToScene() will then transform the adjusted rect to scene coordinates. – Roman Schaub Jan 20 '20 at 08:12