根据QWidget 或 QGraphicWidget体系调整所需要继承或更新的类实现
/* 头文件 */
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
protected:
void paintEvent(QPaintEvent *event);
}
/* cpp文件 */
MainWindow::MainWindow(QWidget *parent): QMainWindow(parent) { /*定时更新*/ QTimer *timer = new QTimer(this); connect( timer, SIGNAL(timeout()), this, SLOT( update() ) ); timer->start(50); } void MainWindow::paintEvent(QPaintEvent *event) { QPainter painter(this); QString pathName = "/home/test.png"; QImage sourceImage; sourceImage.load(pathName); painter.setRenderHint( QPainter::Antialiasing ); QColor quadColor( 0, 0, 255 ); painter.setBrush( quadColor ); QTime time = QTime::currentTime(); painter.translate( 100, 100 ); painter.rotate( ( time.second() + ( time.msec() / 1000.0 ) ) * 6.0 ); /*下行为画出一个正方行旋转*/ //painter.drawRect( QRect( -50, -50, 100, 100 ) ); /* 下行将图片画出旋转, -50,-50 为旋转中心。 */ painter.drawImage(QRect(-50, -50, sourceImage.width(), sourceImage.height()), sourceImage); }