hi
How to rotate the rectangle about its origin. i have tried first by rotating the matrix and the calculating the distance between the topLeft() corner of a rectangle and the distance to which it has rotated ,and then translating it.I am unable to rotate about origin of rectangle, But i am able to rotate around the topLeft() corner of the rectangle.
Here is some code which rotates the about the topLeft() of a rectangle .Please help modify the code to make the rectangle rotate around its centre.
#include <QtGui>
{
Q_OBJECT
public:
{
QRect rect
(20,
20,
150,
100);
matrix.translate(rect.left(), rect.top());
static int degree=0;
matrix.rotate(++degree);
painter.setMatrix(matrix);
rect.setX(0);rect.setY(0);
painter.drawRect(rect);
painter.drawPoint(rect.center());
QTimer::singleShot(100,
this,
SLOT(update
()));
}
};
int main(int argc, char *argv[])
{
a.setStyleSheet("QWidget{background: white}");
Widget w;
w.show();
return a.exec();
}
#include "main.moc"
#include <QtGui>
class Widget : public QWidget
{
Q_OBJECT
public:
void paintEvent(QPaintEvent * event)
{
QMatrix matrix;
QRect rect(20,20,150,100);
matrix.translate(rect.left(), rect.top());
static int degree=0;
matrix.rotate(++degree);
QPainter painter(this);
painter.setMatrix(matrix);
rect.setX(0);rect.setY(0);
painter.drawRect(rect);
painter.drawPoint(rect.center());
QTimer::singleShot(100,this, SLOT(update()));
}
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setStyleSheet("QWidget{background: white}");
Widget w;
w.show();
return a.exec();
}
#include "main.moc"
To copy to clipboard, switch view to plain text mode
Bookmarks