Qt之简单图片浏览器

本文介绍了使用Qt框架创建一个简单的图片浏览器,支持鼠标滚轮缩放、定时自动播放及切换图片功能。通过QTimer实现定时播放,QWheelEvent处理滚轮事件,QVector作为图片容器并实现循环链表。
摘要由CSDN通过智能技术生成

功能介绍

  • 支持鼠标滚轮放大缩小
  • 支持定时自动播放
  • 支持下一张或下一张图片

说明:功能比较简单(大牛勿喷),就是封装了一层。基本上没有代码的注释,如果大概意思不懂,那么就是笔者写代码的功底不够。


所需知识

  • 定时器(QTimer)
  • 滚轮事件(QWheelEvent)
  • 容器(QVector)
  • 链表(QVector实现循环链表)

代码展示

//pictureviewwidget.h
#ifndef PICTUREVIEWWIDGET_H
#define PICTUREVIEWWIDGET_H

#include <QWidget>
#include <QVector>
#include <QPixmap>

class QPushButton;
class QLabel;
class QTimer;

class PictureViewWidget : public QWidget
{   
    Q_OBJECT
public:
    PictureViewWidget(QVector<QPixmap *> &pictures);

private:
    void setupUI();

    // (width, height) = (800 * scale, 600 * scale)
    void showPicture(float scale = 1.0);  

private slots:
    void nextPicture();
    void prevPicture();

    // Play images, and interval is 2s
    void playPictures();

    // Reimplement the wheelEvent() to achieve 
    // zoom in and zoom out       
    void wheelEvent(QWheelEvent * event);

private:
    QVector<QPixmap *>  &pictures_;
    QLabel              *pictureLabel;
    QPushButton         *prevButton;
    QPushButton         *nextButton;
    QPushButton         *playButton;

    bool    isPlaying;      // Status of playing pictures 
    QTimer *timer;          // Auto play with specific interval  
    int     currentIndex;   // Index of current picture
    int     size;           
  • 3
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值