Chinaunix首页 | 论坛 | 博客
  • 博客访问: 773707
  • 博文数量: 2
  • 博客积分: 1255
  • 博客等级: 少校
  • 技术积分: 856
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-23 13:19
个人简介

停更

文章分类

全部博文(2)

分类: Windows平台

2013-01-30 19:38:43

QT在我脑海里是一个服务,很显然是个可扩展性非常好的数据库。使用QT我感觉非常轻松,因为我从来没有可以去记过QT里任何的类的成员,但是每种一定功能的代码我都会保留下来让我可以快速查找,下次要使用则可以借鉴,我要做的仅是保持一个清醒的大脑。

让你的大脑成为CPU,而不是数据库。知识是静态的,现在互联网之广博,只要你想,你可以学习任何一方面的知识,但是只有动态的知识才是有价值的。

下面的要说的截图程序,我尽量帮需求做得通用,以便以后能很快地作为子功能加入别的软件。记录下来给方便自己查找。功能暂时做得很简陋,但是以后会持续更新。

功能:打开软件则会抓取一张当前桌面的图片,询问是否保存。输入文件名及图片类型点save击或者回车则可以保存在默认路径(该程序的所在目录)。保存文件成功之后退出。

使用相关类: QPixmap QDeskTopWidget QDir QMessageBox

 

dialog.h

#ifndef DIALOG_H
  #define DIALOG_H
  #include
  #include
  #include
  #include
  #include
  #include
  namespace Ui {
     class Dialog;
  }
  class Dialog : public QDialog
  {
     Q_OBJECT
  public:
     explicit Dialog(QWidget *parent = 0);
     ~Dialog();
  private slots:
     void saveScreen();
     void grabScreen();
  private:
     Ui::Dialog *ui;
     QPixmap screen;
  };
  #endif // DIALOG_H

 

dialog.cpp

  #include "dialog.h"
  #include "ui_dialog.h"
  Dialog::Dialog(QWidget *parent) :
     QDialog(parent),
     ui(new Ui::Dialog)
  {
     ui->setupUi(this);
     this->setWindowTitle("Screen sh0o0ter");
     connect(ui->save_button,SIGNAL(clicked()),this,SLOT(saveScreen()));
     connect(ui->cancel_button,SIGNAL(clicked()),this,SLOT(close()));
     ui->savePath_label->setText(tr("当前文件保存在:")+QDir::currentPath());
     this->grabScreen();
  }
  Dialog::~Dialog()
  {
     delete ui;
  }
  void Dialog::grabScreen()
  {
     this->hide();//hide this widget
     screen = QPixmap::grabWindow(QApplication::desktop()->winId());
     ui->label->setPixmap(screen.scaled(ui->label->size()));
     this->show();//show this widget informing to save or not
  }
  void Dialog::saveScreen()
  {
     //default: save in program location
     if(ui->saveName_line->text().isEmpty()){
         QMessageBox::information(this,"File name error!","Please input a file name.");
         return;
     }
     QString filename = ui->saveName_line->text();
     if(screen.save(filename)){
         QMessageBox::information(this,"Accept.","File saved.");
         this->close();     //save and close
     }else{
         QMessageBox::information(this,"Warnning.","File name should add file types.like *.JPG");
     }
  }

欢迎大家交流,我的邮箱noiplee@gmail.com

这是noiplee的技术博客,我写博客的目的是想通过快速分享来达到掌握知识的目的,同时希望和各位网友交流共同进步。我经常关注linux,嵌入式,读书,思维导图,冥想等领域。如果您看了我的文章有任何的建议或者观点,非常欢迎留言和评论,有任何问题我们都可以一起探讨,我会及时回复的。

 

 

 

阅读(5300) | 评论(0) | 转发(0) |
0

上一篇:Qt Opencv 在Linux下摄像头简单示例v1.0

下一篇:没有了

给主人留下些什么吧!~~