亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Qt通過(guò)圖片組繪制動(dòng)態(tài)圖片

 更新時(shí)間:2020年07月12日 11:40:55   作者:weixin_45752304  
這篇文章主要為大家詳細(xì)介紹了Qt通過(guò)圖片組繪制動(dòng)態(tài)圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Qt通過(guò)圖片組繪制動(dòng)態(tài)圖片的具體代碼,供大家參考,具體內(nèi)容如下

任務(wù)實(shí)現(xiàn):

通過(guò)定時(shí)器的使用來(lái)依次調(diào)用資源文件中的靜態(tài)圖片文件,從而達(dá)到是圖片中內(nèi)容動(dòng)起來(lái)的效果;

效果實(shí)現(xiàn):

實(shí)現(xiàn)過(guò)程:

1.通過(guò)paintEvent()函數(shù)進(jìn)行每一張圖片的導(dǎo)入平鋪繪制;
2.通過(guò)timerEvent()函數(shù)對(duì)每一張圖片按照設(shè)定的時(shí)間進(jìn)行重復(fù)的調(diào)用,從而達(dá)到動(dòng)圖的效果;
3.通過(guò)自定義InitPixmap()函數(shù)來(lái)對(duì)每一張圖片進(jìn)行初始化,將其導(dǎo)入到Pixmap[ 64 ]組中;

整體代碼:

dialog.h

#ifndef DIALOG_H
#define DIALOG_H


#include <QDialog>


QT_BEGIN_NAMESPACE
namespace Ui { class Dialog; }
QT_END_NAMESPACE


class Dialog : public QDialog
{
  Q_OBJECT


public:
  Dialog(QWidget *parent = nullptr);
  ~Dialog();


  void paintEvent(QPaintEvent *event);

  void timerEvent(QTimerEvent *event);

  int curIndex;
  
  void InitPixmap();


private:


    QPixmap pixmap[64];
  Ui::Dialog *ui;
};
#endif // DIALOG_H

dialog.cpp

#include "dialog.h"
#include "ui_dialog.h"
#include <QPainter>
#include <QPixmap>


Dialog::Dialog(QWidget *parent)
  : QDialog(parent)
  , ui(new Ui::Dialog)
{
  ui->setupUi(this);
  resize(160,182);
  startTimer(100);
  curIndex = 0;


  InitPixmap();
}


Dialog::~Dialog()
{
  delete ui;
}


void Dialog::paintEvent(QPaintEvent *event)
{


  QPainter painter(this);
  QRect q(0,0,80,91);
  QRect q2(0,0,2*80,2*91);


  painter.drawPixmap(q2,pixmap[curIndex],q);


}


void Dialog::timerEvent(QTimerEvent *event)
{


  curIndex++;
  if(curIndex>=64)
  {
    curIndex=0;
  }


  repaint();
}

void Dialog::InitPixmap()
{


  for(int i=0;i<64;i++)
  {
    QString filename = QString(":/Res/Resourse/1_%1.png").arg(i+1,2,10,QLatin1Char('0'));
    QPixmap map(filename);


    pixmap[i]=map;
  }
  
}

調(diào)用過(guò)程

1.通過(guò)InitPixmap()函數(shù)將六十四張圖片保存在Pixmap數(shù)組中;
2.通過(guò)paintEvent()函數(shù)依次調(diào)用圖片;
3.通過(guò)timerEvent()函數(shù)來(lái)設(shè)定調(diào)用的循環(huán);
4在主函數(shù)中通過(guò)定時(shí)器設(shè)定調(diào)用間隔為100ms;

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論