一、前言
使用 Qt 制作了一个简单的图片播放器,点击 "浏览按钮" 浏览图片所在目录,目录中的所有图片缩小图标和名称会显示在左侧的图片列表中,点击列表中的图片项,可以在右侧区域的标签上显示或播放 png、img、gif 等格式图片。示意图如下所示:
二、工程代码
具体代码如下:
头文件 imgPlayer.h
#ifndef IMGPLAYER_H
#define IMGPLAYER_H
#include <QMainWindow>
#include <QFileDialog>
#include <QMovie>
#include <QDebug>
namespace Ui {
class ImgPlayer;
}
class ImgPlayer : public QMainWindow
{
Q_OBJECT
public:
explicit ImgPlayer(QWidget *parent = nullptr);
~ImgPlayer();
private slots:
void on_openImgButton_clicked(); //浏览按钮-点击槽函数
void on_imgListWidget_clicked(const QModelIndex &index); //图片列表-点击槽函数
private:
Ui::ImgPlayer *ui;
QString m_imgDirPath; // 图片所在目录的具体路径
}