PDA

View Full Version : How to save screenshot?



xleniz
20th March 2013, 23:14
Hi, im on Linux, and Im trying to save a screenshot.
I read that QPixmap::grabWindow() is deprecated, and that I should use QScreen::grabWindow() instead.
So I did.
The problem is: The image is not being saved right, and does not show up the correct part of screen (only 4 parts of screen, upside down and in all kind of ways).

This ma code.


void Widget::on_pushButton_clicked()
{
QScreen *QSCREEN = QGuiApplication::primaryScreen();
QPixmap qpix = QSCREEN->grabWindow(this->winId(), 0, 0, QApplication::desktop()->width(),
QApplication::desktop()->height());
qpix.save("/home/marcus/Bilder/Hello.png");
}

qt_gotcha
4th April 2013, 20:36
void shootScreen()
{
QPixmap originalPixmap; // clear image for low memory situations

originalPixmap = QPixmap::grabWidget(tabWidget->currentWidget()); //<== some widget

QString format = "png";

QString fileName = "myshot.png";

originalPixmap.save(fileName, format.toAscii());

}