class MyWidget : public QWidget
{
Q_OBJECT
enum
{
IMG_WIDTH = 80,
IMG_HEIGHT = 30,
};
public:
MyWidget()
: m_arg(0), m_pmp(IMG_WIDTH, IMG_HEIGHT)
{
resize(400, 300);
QPainter p(&m_pmp);
p.drawText(10, 10, tr("Hello World!"));
startTimer(30);
}
void paintEvent(QPaintEvent * e)
{
QPainter p(this);
QSize sz = size();
p.translate(sz.width() / 2, sz.height() / 2);
p.rotate(m_arg);
p.drawPixmap(- IMG_WIDTH / 2, - IMG_HEIGHT / 2, IMG_WIDTH, IMG_HEIGHT, m_pmp, 0, 0, IMG_WIDTH, IMG_HEIGHT);
}
void timerEvent(QTimerEvent * e)
{
m_arg += 1;
update();
}
private:
qreal m_arg;
QPixmap m_pmp;
};