[Qt-interest] QGraphicsSceneItem Rotate an object using the center of object
Samuel Rødal
sroedal at trolltech.com
Thu Jan 22 10:52:15 CET 2009
Jesús Fernández wrote:
> Hi,
>
> I need to rotate an object but I need to use the center of the object as
> the center of coordinates system, which is the best method to do this?
>
> Thanks
Hi,
either you can make sure your item is centered at the origin by having
the boundingRect() function return a rect with center (0, 0) and doing
your painting appropriately, or you can do a translate to the item's
center, the rotate, and then the inverse translate. Example:
QPointF center = item->boundingRect().center();
item->translate(center.x(), center.y());
item->rotate(angle);
item->translate(-center.x(), -center.y());
Regards,
Samuel
More information about the Qt-interest-old
mailing list