Tomasz Nowakowski
Tomasz Nowakowski

Reputation: 19

How to grab Window using Qt on linux?

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

Answers (1)

zziyaa
zziyaa

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

Related Questions