PDA

View Full Version : QGraphicsRectItem



c_srikanth1984
29th July 2009, 09:50
Hi
I have a QGraphicsScene scene and Item which inherits the QGraphicsRectItem properties. I am taking points from scene MousePressEvent and MouseReleseevents and Drawing a Rectangle with

QRect(TopLeft,BottomRight)
with both points(MousePressEvent and MouseReleseevents ).
Whem I say

item->rotate(qreal);
the item is been rotated from the topleft point where as i want it to rotate from center of the Rectangle.
Hope u got my point. So, What i need to do to rotate item from its center point.

yogeshgokul
29th July 2009, 10:04
What i need to do to rotate item from its center point.
By-default the rotation point it the origin of that item i.e. topleft corner.
To translate around an arbitrary point (x, y), you need to combine translation and rotation with setTransform().


Example:

// Rotate an item 45 degrees around (0, 0).
item->rotate(45);

// Rotate an item 45 degrees around (x, y).
item->setTransform(QTransform().translate(x, y).rotate(45).translate(-x, -y));