#include "m_widget.h"m_widget::m_widget(QWidget *parent) : QWidget(parent){ m_cruuentIndex = 0; m_png = ":/Images/soft_anim.png"; QPixmap pix(m_png); m_num = 17; for(int i=0; i != m_num; i++) { m_pixmaplist.append(pix.copy(i*(pix.width()/m_num), 0, pix.width()/m_num, pix.height())); } m_currentPix = m_pixmaplist.at(0); this->setFixedSize(m_currentPix.size()); update(); m_clockTimer = new QTimer(this); m_clockTimer->setInterval(80); connect(m_clockTimer, SIGNAL(timeout()), this, SLOT(my_update())); m_clockTimer->start();}void m_widget::my_update(){ if(m_cruuentIndex != m_num) { m_currentPix = m_pixmaplist.at(m_cruuentIndex); update(); if(m_cruuentIndex == (m_num - 1)) { m_clockTimer->stop(); m_cruuentIndex = 0; } m_cruuentIndex++; }}void m_widget::enterEvent(QEvent *){ m_clockTimer->start();}void m_widget::paintEvent(QPaintEvent *){ QPainter painter(this); painter.drawPixmap(rect(), m_currentPix);}上面的代码既是把包含多张图片的一张图片制作成一个动画的实例。
qt 利用多张图片做成动画实例
最新推荐文章于 2024-07-11 23:28:59 发布