cbeall1
5th March 2006, 17:05
Hi,
I'm trying to rotate several canvas items around their own center. I read on this forum and in other places that I need to translate the painter, rotate it, paint on it, and then restore it to its former state. I've tried this (or so I think), but I must be missing something. The rotation doesn't work properly, and with the painter translation/rotation code added, even boxes with a rotation of 0 show up in the wrong place.
I've attached two screenshots: The first of the boxes without any translation/rotation code used. And the second code shows what happens when I add the translate/rotate funtions. Notice that even the unrotated boxes are translated, but they should be in exactly the same place as in the first screenshot. (The images are the same scale). The rotated boxes are placed at the same coordinates as the unrotated ones, so they should overlap if the code worked properly. Rotation is 55 and 19 degrees.
http://www.ece.utk.edu/~beall/original.png
http://www.ece.utk.edu/~beall/rotation.png
Here is my code from drawShape
void MSPBox::drawShape(QPainter &painter)
{
painter.translate(x(), y());
painter.rotate(rotate);
QCanvasRectangle::drawShape(painter);
painter.drawText(rect(), AlignCenter, text());
painter.rotate(-rotate);
painter.translate(-x(), -y());
cout << rotate << " is the angle" << endl;
}
Thanks for any suggestions!
I'm trying to rotate several canvas items around their own center. I read on this forum and in other places that I need to translate the painter, rotate it, paint on it, and then restore it to its former state. I've tried this (or so I think), but I must be missing something. The rotation doesn't work properly, and with the painter translation/rotation code added, even boxes with a rotation of 0 show up in the wrong place.
I've attached two screenshots: The first of the boxes without any translation/rotation code used. And the second code shows what happens when I add the translate/rotate funtions. Notice that even the unrotated boxes are translated, but they should be in exactly the same place as in the first screenshot. (The images are the same scale). The rotated boxes are placed at the same coordinates as the unrotated ones, so they should overlap if the code worked properly. Rotation is 55 and 19 degrees.
http://www.ece.utk.edu/~beall/original.png
http://www.ece.utk.edu/~beall/rotation.png
Here is my code from drawShape
void MSPBox::drawShape(QPainter &painter)
{
painter.translate(x(), y());
painter.rotate(rotate);
QCanvasRectangle::drawShape(painter);
painter.drawText(rect(), AlignCenter, text());
painter.rotate(-rotate);
painter.translate(-x(), -y());
cout << rotate << " is the angle" << endl;
}
Thanks for any suggestions!