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

QT實(shí)現(xiàn)圖片輪播

 更新時(shí)間:2020年06月08日 08:29:55   作者:男銀的驕傲  
這篇文章主要介紹了QT實(shí)現(xiàn)圖片輪播,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了QT實(shí)現(xiàn)圖片輪播的具體代碼,供大家參考,具體內(nèi)容如下

UI設(shè)計(jì)

一個(gè)Qlabel控件,一個(gè)pushButton 鍵

廢話(huà)不多說(shuō)直接懟代碼

.h文件

#ifndef IMAGES_H
#define IMAGES_H
 
#include <QtWidgets/QMainWindow>
#include "ui_images.h"
#include <Qlabel>
#include <qpushbutton.h>
#include <qpixmap.h>
#include <qstring.h>
#include <qtimer.h>
 
class images : public QMainWindow
{
 Q_OBJECT
 
public:
 images(QWidget *parent=0);
 ~images();
 
private:
 Ui::imagesClass ui;
 QTimer *qTimer;
 int imgNumber;
private slots:
 //顯示圖片
 void showPictureSlot();
 
};
 
#endif // IMAGES_H

.cpp文件

#include "images.h"
#pragma execution_character_set("utf-8")
 
images::images(QWidget *parent)
 : QMainWindow(parent), imgNumber(0)
{
 ui.setupUi(this);
 //修改標(biāo)題
 this->setWindowTitle("QLabel的顯示圖片程序:");
 
 //給label設(shè)置新的文本
 ui.picture_label->setText("未顯示圖片");
 //將label框的內(nèi)容位于中間.
 ui.picture_label->setAlignment(Qt::AlignCenter | Qt::AlignHCenter);
 
 
 //設(shè)置label框自動(dòng)填充
 //ui.picture_label->setScaledContents(true);
 
 //連接信號(hào) 與 槽
 connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(showPictureSlot()));
 
 
 ui.picture_label->setScaledContents(true);
 
 qTimer = new QTimer();
 
 connect(this->qTimer, SIGNAL(timeout()), this, SLOT(showPictureSlot()));
 
 qTimer->start(3000);
}
 
images::~images()
{
 delete qTimer;
}
//顯示圖片
void images::showPictureSlot(){
 ++imgNumber;
    //圖片路徑(絕對(duì)路徑拼接)
 QString path = ":/File/Resources/" + QString::number(imgNumber) + ".png";
 QPixmap pixmap(path);
 
 pixmap.scaled(ui.picture_label->size(), Qt::KeepAspectRatio);
 
 ui.picture_label->setPixmap(pixmap);
 
 if (3 == imgNumber)
 {
 imgNumber = 0;
 }
}

這樣簡(jiǎn)單的圖片輪播在Qlabel上就 實(shí)現(xiàn)了.

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

相關(guān)文章

最新評(píng)論