PDA

View Full Version : How to rotate an object by its center?



tszzp
10th November 2009, 03:04
How to rotate(such as rectangle) an object by its center? I find the QPainter::rotate function is rotating an object by the point(0,0), not its center. So who can tell me how to do it? I use the QPainter::translate function before using the QPainter::rotate function,find it also work incorrect. Can you give me a simple sample to do it? thanks.

yogeshgokul
10th November 2009, 04:25
How to rotate(such as rectangle) an object by its center? I find the QPainter::rotate function is rotating an object by the point(0,0), not its center. So who can tell me how to do it? I use the QPainter::translate function before using the QPainter::rotate function,find it also work incorrect. Can you give me a simple sample to do it? thanks.
You need to translate your object's center to origin(the point of rotation), then rotate it and then re-translate it to its original position to get rotation from center.
You can use QTransform for this.
Click here for more info (http://doc.trolltech.com/4.5/painting-transformations.html).