#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->label->installEventFilter(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
//bool MainWindow::eventFilter(QObject *obj, QEvent *event)
//{
// if(obj == ui->label)
// {
// if(event->Style == QEvent::MouseButtonDblClick)
// {
// QMouseEvent *e = static_cast<QMouseEvent *>(event);
// if(e->button() == Qt::LeftButton)
// {
// QMouseEvent *eNew = new QMouseEvent(QEvent::MouseButtonDblClick, e->pos(), e->button(), e->buttons(), e->modifiers());
// QApplication::postEvent(ui->pushButton, eNew);
// return true;
// }
// }
// }
// return QMainWindow::eventFilter(obj, event);
//}
void MainWindow::on_pushButton_clicked()
{
QPixmap fullScreen;
int screenWidget = 640; //屏幕尺寸设置,自己要写别的函数修改尺寸的改这里
int screenHight = 480;
//就是这一步截取了全屏
fullScreen = QPixmap::grabWindow(QApplication::desktop()->winId(),0,0,screenWidget,screenHight);
//这一步是设置弹出框询问保存位置和命名的,要自己修改位置和命名的改这里
// QFileDialog::Options options;
// QString selectedFilter;
// QString fileName = QFileDialog::getSaveFileName(this,
// tr("Save picture"),
// "savescreen.jpg",
// &selectedFilter,
// options);
// QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
// "/home/tom/zhangcong/untitled.png",
// tr("Images (*.png *.xpm *.jpg)"));
// QString pathName = "/home/tom/zhangcong/";
QString pathName = QCoreApplication::applicationDirPath() + "/";
QString fileName = pathName + QDateTime::currentDateTime().toString("yyyyMMddhhmmss") +".jpg";
// //设置截图区域,截图区域是从整屏幕截图中复制相应的区域,要自己写函数的改这里
// int x = 0;
// int y = 0;
// int w = 640;
// int h = 480;
/****************************以下几步是正常的保存QPixmap,可以不转QIameg****************************/
// fullScreen = fullScreen.copy(x,y,w,h); //截取区域改这里
fullScreen.save(fileName,"JPG"); //需要有保存对话框的这么写
if(fullScreen.save(fileName,"JPG"))
qDebug("----------save screen success----------");
/**************以下几步是针对嵌入式系统,图像位数有限制,转为了8位的图像,PC端可以不需要**************/
// QImage image = fullScreen.toImage();
// // image = image.copy(x,y,w,h); //截取区域改这里
// //转8位
// image = image.convertToFormat(QImage::Format_Indexed8,Qt::AutoColor);
// //image.save(fileName,"JPG") 需要有保存对话框的这么写
// if(image.save("/savescreen.jpg","JPG"))
// qDebug("----------save screen success----------");
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
label双击截屏.rar (19个子文件)
label双击截屏
build-PrintScreen-Desktop-Debug
moc_mainwindow.cpp 3KB
main.o 144KB
PrintScreen 537KB
mainwindow.o 288KB
20150623145551.jpg 35KB
printscreenlabel.o 158KB
Makefile 11KB
moc_mainwindow.o 155KB
moc_printscreenlabel.o 158KB
moc_printscreenlabel.cpp 3KB
ui_mainwindow.h 4KB
PrintScreen
mainwindow.ui 3KB
printscreenlabel.cpp 2KB
PrintScreen.pro 416B
PrintScreen.pro.user 18KB
printscreenlabel.h 714B
mainwindow.cpp 3KB
main.cpp 176B
mainwindow.h 602B
共 19 条
- 1
资源评论
追风聪
- 粉丝: 2
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功