How to grab Window using Qt on linux?

1.8k Views Asked by At

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.

1

There are 1 best solutions below

0
zziyaa On
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