Last active
August 29, 2015 14:07
-
-
Save fecub/75e3660bfa12725ad6a6 to your computer and use it in GitHub Desktop.
How to Qt screenshot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QPixmap> | |
#include <QDir> | |
#include <QFileDialog> | |
#include <QString> | |
#include <QScreen> | |
QPixmap originalPixmap; | |
originalPixmap = QPixmap(); // clear image for low memory situations | |
// on embedded devices. | |
//! [5] | |
QScreen *screen = QGuiApplication::primaryScreen(); | |
if (screen) | |
originalPixmap = screen->grabWindow(0); | |
QString format = "png"; | |
QString initialPath = QDir::currentPath() + QObject::tr("/untitled.") + format; | |
// QString fileName = QFileDialog::getSaveFileName(0,QObject::tr("Save As"), | |
// initialPath, | |
// QObject::tr("%1 Files (*.%2);;All Files (*)") | |
// .arg(format.toUpper()) | |
// .arg(format)); | |
QString fileName = "C:\\path\\to\\file\\testscreenshot.png"; | |
if (!fileName.isEmpty()) | |
originalPixmap.save(fileName, format.toLatin1().constData()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment