Finally i am able to rotate the rectangle about its origin.Below is the working code.
#include <QtGui>
{
Q_OBJECT
public:
{
painter.translate(150,150);
painter.drawRect(rect);
static qreal degree=0;
painter.rotate(++degree);
painter.translate(-rect.width()/2,-rect.height()/2);
painter.drawRect(rect);
painter.drawPoint(rect.center());
QTimer::singleShot(0,
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)
{
QRect rect(0,0,150,100);
QPainter painter(this);
painter.translate(150,150);
painter.drawRect(rect);
static qreal degree=0;
painter.rotate(++degree);
painter.translate(-rect.width()/2,-rect.height()/2);
painter.drawRect(rect);
painter.drawPoint(rect.center());
QTimer::singleShot(0,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
It's strictly about doing anything concerning application logic in a paint event
Please tell the mistake in my program and how to avoid it.How would u have killed it.
Bookmarks