图片的功能

源码:

wiget.h

#ifndef WIDGET_H
#define WIDGET_H
#include <QPixmap>
#include <QImage>
#include <QPushButton>
#include <QHBoxLayout>
#include <QScrollArea>
#include <QLabel>
#include <QWidget>
#include <QPalette>
#include <QTimer>
#include <QString>
#include <QPainter>
#include <QPaintEvent>
#include <QDebug>
#include <QFileDialog>
#include <QStringList>
#include <QMessageBox>
#include <QDir>
#include <QFile>
namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT  
public:
    explicit Widget(QWidget *parent = 0);
    ~Widget();
    QLabel *label;
    QTimer *timer;
    QPixmap pix;

private slots:
    void W_timergo();
    void W_go();
    void W_back();
    void W_close();
    void W_start();
    void W_stop();
    void W_max();
    void W_min();
    void W_flip();
    void W_delete();
    void W_open();
private:
    Ui::Widget *ui;
};

#endif // WIDGET_H

wiget.cpp

#include "widget.h"
#include "ui_widget.h"
static int num;
static int flag=1;
QString image[3] = {":/prefix1/1.jpg",":/prefix1/2.jpg",":/prefix1/3.jpg"};
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    QPixmap pix;

    label = new QLabel;
    timer = new QTimer;
    QPalette palette;

    ui->scrollArea->setWidget(label);
    ui->scrollArea->setAlignment(Qt::AlignCenter);

    palette.setBrush(QPalette::Background,QBrush(QPixmap(":/prefix1/4.jpg")));
    this->setPalette(palette);

    connect(timer,SIGNAL(timeout()),this,SLOT(W_go()));
    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(W_go()));
    connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(W_close()));
    connect(ui->pushButton_4,SIGNAL(clicked()),this,SLOT(W_start()));
    connect(ui->pushButton_5,SIGNAL(clicked()),this,SLOT(W_stop()));
    connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(W_back()));
    connect(ui->pushButton_6,SIGNAL(clicked()),this,SLOT(W_max()));
    connect(ui->pushButton_7,SIGNAL(clicked()),this,SLOT(W_min()));
    connect(ui->pushButton_8,SIGNAL(clicked()),this,SLOT(W_flip()));
    connect(ui->pushButton_9,SIGNAL(clicked()),this,SLOT(W_delete()));
    connect(ui->pushButton_10,SIGNAL(clicked()),this,SLOT(W_open()));

}
void Widget::W_timergo()
{
   pix.load(image[num]);
   label->setPixmap(pix);
   if(num==2)
   {
        num = -1;

   }
   num++;
}
void Widget::W_go()
{
    timer->stop();
    pix.load(image[num]);
    label->setPixmap(pix);
    if(num==2)
    {
         num = -1;

    }
    num++;
}
void Widget::W_back()
{
    if(num < 0)
    {
        num = 2;

    }
    timer->stop();
    pix.load(image[num]);
    label->setPixmap(pix);
    num--;

}
void Widget::W_close()
{
    this->close();

}
void Widget::W_start()
{

     timer->start(2000);

}
void Widget::W_stop()
{
    timer->stop();
}
void Widget::W_max()
{
    timer->stop();
    float MaxX,MaxY;
    MaxX = pix.height();
    MaxY = pix.width();

    pix = pix.scaled(MaxX*2,MaxY*2,Qt::KeepAspectRatio);
    label->setPixmap(pix);





}
void Widget::W_min()
{
    timer->stop();
    float MaxX,MaxY;
    MaxX = pix.height();
    MaxY = pix.width();

    pix = pix.scaled(MaxX/2,MaxY/2,Qt::KeepAspectRatio);
    label->setPixmap(pix);

}
void Widget::W_flip()
{

    timer->stop();
    QMatrix leftmatrix;
    leftmatrix.rotate(90*flag);
    flag++;
    if(flag == 4)
    {
        flag = 0;

    }
    label->setPixmap(QPixmap(image[num]).transformed(leftmatrix,Qt::SmoothTransformation));




}
void Widget::W_delete()
{
    timer->stop();
    QStringList list;
    list=QFileDialog::getOpenFileNames(this,"open image","/","*.jpg");
    qDebug()<<list.at(0);
    pix.load(list.at(0));
    label->setPixmap(pix);
    QMessageBox::StandardButton rb = QMessageBox::question(NULL,"Warning",
                    "Do you want to delete the picture?

",QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
       if(rb == QMessageBox::Yes)
       {


           QFile::remove(list.at(0));//刪除文件

       }
}
void Widget::W_open()
{
    timer->stop();
    QStringList list;
    list=QFileDialog::getOpenFileNames(this,"open image","/","*.jpg");

     qDebug()<<list.at(0);
    pix.load(list.at(0));
    label->setPixmap(pix);
}
Widget::~Widget()
{
    delete ui;
}

main.cpp

#include "widget.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();

    return a.exec();
}


Qt 图片浏览器 实现图片的放大缩小翻转等功能的更多相关文章

  1. Android 图片浏览器 从原来位置放大至全屏显示

    android 图片浏览器 特点: 1.从网络加载图片,只需要传图片地址数组即可 2.点击图片,从原来位置放大至全屏 3.支持手势操作 4.完全自定义布局 项目源码请到GitHub下载:https:/ ...

  2. wxParse解析富文本内容使点击图片可以选中并实现放大缩小

    wxParse解析富文本内容不多说,之前写过步骤介绍,主要是在使用过程中发现解析的富文本内容里有图片时有的可以点击放大缩小,有的点击却报错,找不到imgUrls. 经过排查发现:循环解析的富文本内容正 ...

  3. Js图片缩放代码 鼠标滚轮放大缩小 图片向右旋转

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. c# 调用系统默认图片浏览器打开图片

    private void OpenImage(string fileName) { try { Process.Start(fileName); } catch (Exception ex) { // ...

  5. 调Windows 7的图片浏览器查看图片

    public static void viewPicFromWindows(string pPicPath) { if (pPicPath!="" && Syste ...

  6. 使用qt写的简单的图片浏览器

    功能特别简单,支持png,jpg,bmp,gif文件,支持自适应窗口大小,支持放大缩小,旋转功能还有点问题,支持上下按键选择图片 因为初学qt,所以很多东西都不太会,而且c++学的不是太好,没有怎么使 ...

  7. JS微信网页使用图片预览(放大缩小)

    前言 需求在微信网页中客户点击图片可进行预览放大缩小功能,网上找了各种js方式实现, 唯一的麻烦就是不兼容或者和项目框架不兼容 次函数只只用于部分客户端,否则会出现 WeixinJSBridge is ...

  8. 纯JS打造比QQ空间更强大的图片浏览器-支持拖拽、缩放、过滤、缩略图等

    在线演示地址(打开网页后,点击商家图册): http://www.sport7.cn/cc/jiangnan/football5.html 先看一看效果图: 该图片浏览器实现的功能如下: 1. 鼠标滚 ...

  9. [翻译] AGPhotoBrowser 好用的图片浏览器

    AGPhotoBrowser  好用的图片浏览器 https://github.com/andreagiavatto/AGPhotoBrowser A photo browser for iOS6 a ...

随机推荐

  1. BZOJ1685: [Usaco2005 Oct]Allowance 津贴

    [传送门:BZOJ1685] 简要题意: 贝西工作勤勤恳恳,她每月向约翰索要C 元钱作为工资.约翰手上有不少钱,他一共有N 种面 额的钞票.第i 种钞票的面额记作Vi,约翰有Ki 张.钞票的面额设定是 ...

  2. javascript中运算符有哪些? 他们的优先级 呢?

    一元操作符 ++, -- + -(正负)逻辑操作符 ! && ||基本运算符 +, -, *, /, %关系操作符 >, <, >=, <=, ===, ==, ...

  3. nodejs-website

    http://docs.nodejitsu.com/articles/file-system/how-to-read-files-in-nodejs http://nodeapi.ucdok.com/ ...

  4. MySQL Field排序法

    检索 id = 2 or id = 5 or id = 9 or id = 56 or id = 38.然后按照 2 , 5, 9, 56, 38 这个顺序排列,这是题目要求   以下为解决方案: 1 ...

  5. php https链接

    1.安装soap扩展 2.安装openssL 3.代码执行 function  issure($sn){//通过soap链接接口  进行确认是否是正确的sn码    try{        $clie ...

  6. cogs 49. 跳马问题

    49. 跳马问题 ★   输入文件:horse.in   输出文件:horse.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述] 有一只中国象棋中的 “ 马 ” ,在半张 ...

  7. [Python] Format Strings in Python

    Single quotes and double quotes can both be used to declare strings in Python. You can even use trip ...

  8. Volley简单学习使用五—— 源代码分析三

    一.Volley工作流程图: 二.Network     在NetworkDispatcher中须要处理的网络请求.由以下进行处理: NetworkResponse networkResponse = ...

  9. 【分享】School Rumble校园迷糊大王PSP姐姐事件+PS2游戏第一,二学期【带VNR翻译教程】

    7/22/2014 TUE   为「スクールランブル 姉さん事件です」加入了BANDAI PSP的引擎. 校园迷糊大王PSP姐姐事件 下载地址1:http://www.bego.cc/file/689 ...

  10. WIN10 10招

    还有不到两个月的时间,7 月 29 日 Windows 10 就将正式公布,在此之前已经有不少的用户已经使用上了 Windows 10 的预览版.对于那些苦等 Windows 10 的用户来说,幸福非 ...