手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Qt 截取屏幕的小demo

[日期:2011-03-22] 来源:Linux社区  作者:yiyaaixuexi [字体:大 中 小]

screenshot.cpp

  1. #include "screenshot.h"   
  2. #include "ui_screenshot.h"   
  3.   
  4. Screenshot::Screenshot(QWidget *parent) :   
  5.     QMainWindow(parent),   
  6.     ui(new Ui::Screenshot)   
  7. {   
  8.     ui->setupUi(this);   
  9.     QObject::connect(ui->shotScreenButton,SIGNAL(clicked()),this,SLOT(newShotScreenSlot()));   
  10.     QObject::connect(ui->saveButton,SIGNAL(clicked()),this,SLOT(saveScreenSlot()));   
  11.   
  12. }   
  13.   
  14. Screenshot::~Screenshot()   
  15. {   
  16.     delete ui;   
  17. }   
  18.   
  19. void Screenshot::newShotScreenSlot()   
  20. {   
  21.      if(ui->hideCheckBox->isChecked())   
  22.     {   
  23.           this->hide();   
  24.           this->timer =new QTimer;   
  25.   
  26.           QObject::connect(this->timer,SIGNAL(timeout()),this,SLOT(shotScreenSlot()));   
  27.           this->timer->start(ui->timeSpinBox->value()*1000);   
  28.   
  29.      }   
  30.      else  
  31.      {   
  32.            qApp->beep();   
  33.      }   
  34. }   
  35.   
  36. void Screenshot::shotScreenSlot()   
  37. {   
  38.     this->pixmap= QPixmap::grabWindow(QApplication::desktop()->winId());   
  39.     ui->screenLabel->setPixmap(pixmap.scaled(ui->screenLabel->size()));   
  40.     this->timer->stop();   
  41.     this->show();   
  42. }   
  43. #include <QFileDialog>   
  44. #include <QDir>   
  45. #include <QMessageBox>   
  46.   
  47. void Screenshot::saveScreenSlot()   
  48. {   
  49.     QString fileName=QFileDialog::getSaveFileName(this,"Screen Save",QDir::currentPath());   
  50.     if(!fileName.isEmpty())   
  51.     {   
  52.     pixmap.save(fileName);   
  53.   }   
  54.     else  
  55.     {   
  56.         QMessageBox::information(this,"Error Message","Select a  name ");   
  57.         return;   
  58.     }   
  59.   
  60. }  
linux
相关资讯       Qt 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款