Archived:Como fazer uma captura de tela, em Qt
Aquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.
Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated.
Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated.
Esta é uma aplicação de captura de tela, em que "captura" a tela e faz uma imagem da mesma. Aqui o pixmap, permite capturar a janela completa. Você pode salvar esta nova imagem em .jpg.
Dados do artigo
Exemplo de código
Código fonte: Media:Snapshot.zip
Testado com
Aparelho(s): S60 Emulator
Compatibilidade
Plataforma(s): S60 5th Edition
Artigo
Palavras-chave: QFile,QPixmap
Tradução:
Originado de How to take snapshot in Qt
Por valderind4
Última alteração feita por hamishwillee
em 11 Oct 2012
Contents |
Código fonte
Arquivo de cabeçalho
#ifndef SHOOT_H
#define SHOOT_H
#include <QtGui/QWidget>
#include<QPushButton>
#include<QFileDialog>
#include<QLabel>
#include<QFile>
#include<QDir>
#include<QDesktopWidget>
#include<QVBoxLayout>
#include<QPixmap>
class shoot : public QWidget
{
Q_OBJECT
public:
shoot(QWidget *parent = 0);
~shoot();
private slots:
void shotscreen();
void saveScreen();
private:
void updateLabel();
QPixmap originalPixmap;
QVBoxLayout *lay;
QLabel *pixmap;
QPushButton *shootin;
QPushButton *save;
QPushButton *quit;
};
#endif // SHOOT_H
Source File
#include "shoot.h"
#include "ui_shoot.h"
shoot::shoot(QWidget *parent)
: QWidget(parent)
{
pixmap = new QLabel(this);
pixmap->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
pixmap->setAlignment(Qt::AlignCenter);
pixmap->setMinimumSize(240, 160);
shootin=new QPushButton("shoot",this);
save=new QPushButton("Save",this);
quit=new QPushButton("Quit",this);
connect(shootin,SIGNAL(clicked()),this,SLOT(shotscreen()));
connect(save,SIGNAL(clicked()),this,SLOT(saveScreen()));
connect(quit,SIGNAL(clicked()),qApp, SLOT(quit()));
lay=new QVBoxLayout(this);
lay->addWidget(pixmap);
lay->addWidget(shootin);
lay->addWidget(save);
lay->addWidget(quit);
setLayout(lay);
showMaximized();
setStyleSheet("* { background-color:rgb(0,0,0);color:rgb(255,100,50); padding: 7px}}");
}
shoot::~shoot()
{
// No need to delete any object that has got a parent which is properly deleted.
}
void shoot::saveScreen()
{
QString format = "png";
QString initialPath = QDir::currentPath() + tr("/untitled.") + format;
QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"),initialPath,tr("%1 Files (*.%2);;All Files (*)").arg(format.toUpper()).arg(format));
if (!fileName.isEmpty())
originalPixmap.save(fileName, format.toAscii());
}
void shoot::shotscreen()
{
originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());
qApp->beep();
updateLabel();
}
void shoot::updateLabel()
{
pixmap->setPixmap(originalPixmap.scaled(pixmap->size(), Qt::KeepAspectRatio,Qt::SmoothTransformation));
}



(no comments yet)