Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:Como fazer uma captura de tela, em Qt

From Wiki
Jump to: navigation, search

Archived.pngAquivado: 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.

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.

Article Metadata

Exemplo de código
Código fonte: Media:Snapshot.zip

Testado com
Aparelho(s): S60 Emulator

Compatibilidade
Plataforma(s): S60 5th Edition
Symbian

Artigo
Palavras-chave: QFile,QPixmap
Tradução:
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));
 
}

Captura de tela

Screen01001.jpg

Arquivo ZIP

File:Snapshot.zip

This page was last modified on 11 October 2012, at 01:13.
334 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×