Reputation: 19
In windows this is very simple:
auto pixmap = qApp->screens().at(0)->grabWindow(QDesktopWidget().winId());
But grabWindow isn't working on linux. I try something like:
QScreen *screen = QGuiApplication::primaryScreen();
auto pixmap = QPixmap::grabWindow(0);
but with no good result.
Upvotes: 0
Views: 2330
Reputation: 61
QScreen *screen = QGuiApplication::primaryScreen();
QPixmap pixmap = screen->grabWindow(0);
Should work if screen is valid. You can refer to shootScreen method at Qt Screenshot Example
Upvotes: 1