0

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.

  • This is maybe "How to make a screen shot from the window on Linux?". The problem with Linux GUI (not in our app) is that the system GUI can be very different depending on the Linux and even of version of it. It was GNOME and now something else etc. So, that is why Qt is not necessarily able to help. – Alexander V Jul 31 '20 at 20:15
  • 2
    What do you mean by "with no good result"? Note that QPixmap::grabWindow is deprecated since Qt5, you should use [`QScreen::grabWindow`](https://doc.qt.io/qt-5/qscreen.html#grabWindow) instead. – musicamante Jul 31 '20 at 21:27
  • @musicamante I use QScreen::grabWindow(), but when I check pixmap size height I get 0. – Tomasz Nowakowski Aug 01 '20 at 12:14

1 Answers1

0
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

zziyaa
  • 51
  • 2