16,203
社区成员
发帖
与我相关
我的任务
分享
#include <QFileDialog>
#include <QDir>
#include <QMessageBox>
Screenshot::Screenshot(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Screenshot)
{
ui->setupUi(this);
QObject::connect(ui->shotScreenButton,SIGNAL(clicked()),this,SLOT(newShotScreenSlot()));
QObject::connect(ui->saveButton,SIGNAL(clicked()),this,SLOT(saveScreenSlot()));
}
Screenshot::~Screenshot()
{
delete ui;
}
void Screenshot::newShotScreenSlot()
{
if(ui->hideCheckBox->isChecked())
{
this->hide();
this->timer =new QTimer;
QObject::connect(this->timer,SIGNAL(timeout()),this,SLOT(shotScreenSlot()));
this->timer->start(ui->timeSpinBox->value()*1000);
}
else
{
qApp->beep();
}
}
void Screenshot::shotScreenSlot()
{
this->pixmap= QPixmap::grabWindow(QApplication::desktop()->winId());
ui->screenLabel->setPixmap(pixmap.scaled(ui->screenLabel->size()));
this->timer->stop();
this->show();
}
void Screenshot::saveScreenSlot()
{
QString fileName=QFileDialog::getSaveFileName(this,"Screen Save",QDir::currentPath());
if(!fileName.isEmpty())
{
pixmap.save(fileName);
}
else
{
QMessageBox::information(this,"Error Message","Select a name ");
return;
}
}