目录
项目要求
基于作业3.0,增添以下功能:
1. 优化图片和代码逻辑
2. 增加自动翻页功能
3. 增加试试手气功能
项目实现
ui设计
代码
dialog.h
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <QPixmap>
#include <QSize>
#include <QList>
#include <QDebug>
#include <QTimer>
#include <QDateTime>
#include <ctime>
namespace Ui {
class Dialog;
}
class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
private:
Ui::Dialog *ui;
QList<QString> path;
QTimer *timer;
int id;
private slots:
void nextSlot(); //向下翻页的槽函数
void lastSlot(); //向上翻页的槽函数
void zidongSlot();//自动翻页的槽函数
void startSlot(); //启动自动翻页
void stopSlot(); //停止自动翻页
void suijiSlot(); //随机抽取
};
#endif // DIALOG_H
dialog.cpp
#include "dialog.h"
#include "ui_dialog.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog),id(0),timer(new QTimer(this))
{
ui->setupUi(this);
path<<":/new/prefix1/111.jpg"<<":/new/prefix1/222.jpg"<<":/new/prefix1/333.jpg"<<":/new/prefix1/444.jpg";
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(nextSlot()));
connect(ui->pushButton_2, SIGNAL(clicked()), this, SLOT(lastSlot()));
connect(ui->pushButton_3, SIGNAL(clicked()), this, SLOT(startSlot()));
connect(ui->pushButton_4, SIGNAL(clicked()), this, SLOT(suijiSlot()));
connect(ui->pushButton_5, SIGNAL(clicked()), this, SLOT(stopSlot()));
srand(static_cast<unsigned>(time(0)));
connect(timer, SIGNAL(timeout()), this, SLOT(zidongSlot()));
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::nextSlot()
{
id++;
if (id == path.size())
{
id = 0;
}
qDebug() << "下一张";
QPixmap pic(path.at(id));
ui->label->setPixmap(pic);
}
void Dialog::lastSlot()
{
id--;
if (id < 0)
{
id = path.size() - 1;
}
qDebug() << "上一张";
QPixmap pic(path.at(id));
ui->label->setPixmap(pic);
}
void Dialog::zidongSlot()
{
nextSlot();
}
void Dialog::startSlot()
{
qDebug()<<"开启翻页";
timer->start(1000);
}
void Dialog::stopSlot()
{
qDebug()<<"停止翻页";
timer->stop();
}
void Dialog::suijiSlot()
{
id=rand() % path.size();
QPixmap pic(path.at(id));
ui->label->setPixmap(pic);
qDebug() << "随机抽取";
}
源码
已绑定资源置顶
标签:Qt,翻页,void,ui,Dialog,电子相册,include,id From: https://blog.csdn.net/QR70892/article/details/143277074