#include <QtGui>
{
Q_OBJECT
public:
{
QRect rect
(20,
20,
150,
100);
matrix.translate(rect.left(), rect.top());
static int degree=0;
matrix.rotate(++degree);
int OA=sqrt(pow(rect.width(),2) + pow(rect.height(),2))/2;//OA is half the size of, diagonal of the rectangle
int D1=acos(OA*2 / rect.width());
int D=D1+degree;
int ch = OA * cos(D);
int cw = OA * sin(D);
matrix.translate(cw,ch);
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);
int OA=sqrt(pow(rect.width(),2) + pow(rect.height(),2))/2;//OA is half the size of, diagonal of the rectangle
int D1=acos(OA*2 / rect.width());
int D=D1+degree;
int ch = OA * cos(D);
int cw = OA * sin(D);
matrix.translate(cw,ch);
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