Qt 图片浏览器 实现图片的放大缩小翻转等功能
图片的功能
源码:
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 图片浏览器 实现图片的放大缩小翻转等功能的更多相关文章
- Android 图片浏览器 从原来位置放大至全屏显示
android 图片浏览器 特点: 1.从网络加载图片,只需要传图片地址数组即可 2.点击图片,从原来位置放大至全屏 3.支持手势操作 4.完全自定义布局 项目源码请到GitHub下载:https:/ ...
- wxParse解析富文本内容使点击图片可以选中并实现放大缩小
wxParse解析富文本内容不多说,之前写过步骤介绍,主要是在使用过程中发现解析的富文本内容里有图片时有的可以点击放大缩小,有的点击却报错,找不到imgUrls. 经过排查发现:循环解析的富文本内容正 ...
- Js图片缩放代码 鼠标滚轮放大缩小 图片向右旋转
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- c# 调用系统默认图片浏览器打开图片
private void OpenImage(string fileName) { try { Process.Start(fileName); } catch (Exception ex) { // ...
- 调Windows 7的图片浏览器查看图片
public static void viewPicFromWindows(string pPicPath) { if (pPicPath!="" && Syste ...
- 使用qt写的简单的图片浏览器
功能特别简单,支持png,jpg,bmp,gif文件,支持自适应窗口大小,支持放大缩小,旋转功能还有点问题,支持上下按键选择图片 因为初学qt,所以很多东西都不太会,而且c++学的不是太好,没有怎么使 ...
- JS微信网页使用图片预览(放大缩小)
前言 需求在微信网页中客户点击图片可进行预览放大缩小功能,网上找了各种js方式实现, 唯一的麻烦就是不兼容或者和项目框架不兼容 次函数只只用于部分客户端,否则会出现 WeixinJSBridge is ...
- 纯JS打造比QQ空间更强大的图片浏览器-支持拖拽、缩放、过滤、缩略图等
在线演示地址(打开网页后,点击商家图册): http://www.sport7.cn/cc/jiangnan/football5.html 先看一看效果图: 该图片浏览器实现的功能如下: 1. 鼠标滚 ...
- [翻译] AGPhotoBrowser 好用的图片浏览器
AGPhotoBrowser 好用的图片浏览器 https://github.com/andreagiavatto/AGPhotoBrowser A photo browser for iOS6 a ...
随机推荐
- 项目:rbac 基于角色的权限管理系统;
- 简单示意流程图 - RBAC分析: - 基于角色的权限管理: - 权限等于用户可以访问的URL: - 通过限制URL来限制权限: - RBAC表结构组成: from django.db impor ...
- css3透明度
http://www.haorooms.com/post/css_common //透明度 div{ background: #00c2de; opacity: 0.9; filter: alpha( ...
- datatable设置成中文
$('#datatable').DataTable({ language: { "sProcessing": "处理中...", "sLengthMe ...
- Object和其他类型的转换
Object对象是一切类的父类(基类),只要是Object对象,可以强制转换为其他类型.
- SpringMVC与SpringBoot返回静态页面遇到的问题
1.SpringMVC静态页面响应 package com.sv.controller; import org.springframework.stereotype.Controller; impor ...
- tensorflow学习之路---Session、Variable(变量)和placeholder
---恢复内容开始--- 1.Session '''Session.run():首先里面的参数是一个API(函数的接口)的返回值或者是指定参数的值:功能:得知运算结果有两种访问方式:直接建立或者运用w ...
- Tensorflow 学习笔记 -----tf.where
TensorFlow函数:tf.where 在之前版本对应函数tf.select 官方解释: tf.where(input, name=None)` Returns locations of true ...
- C# Arcgis Engine 获得鼠标按下位置的要素
public IFeature GetFeatureOnMouseDown(IPoint point) { try { ILayer layer = Common.GetLayerByName(mMa ...
- sparkR处理Gb级数据集
spark集群搭建及介绍:敬请关注 数据集:http://pan.baidu.com/s/1sjYN7lF 总结:使用sparkR进行数据分析建模相比R大致有3-5倍的提升 查看原始数据集:通过iri ...
- awk依照多个分隔符进行切割
我们知道awk能够进行类似于cut之类的操作.如一个文件data例如以下 zhc-123|zhang hongchangfirst-99|zhang hongchang-100|zhang 假设我们 ...