Taking screenshot of a specific window - C++ / Qt


In Qt, how do I take a screenshot of a specific window (i.e. suppose I had Notepad up and I wanted to take a screenshot of the window titled "Untitled - Notepad")? In their screenshot example code, they show how to take a screenshot of the entire desktop:

originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId());

How would I get the winId() for a specific window (assuming I knew the window's title) in Qt?


11/21/2009 1:43:04 AM

Accepted Answer

I'm pretty sure that's platform-specific. winIds are HWNDs on Windows, so you could call FindWindow(NULL, "Untitled - Notepad") in the example you gave.

11/21/2009 1:46:52 AM

Have a look at Screenshot example

In short:

QScreen *screen = QGuiApplication::primaryScreen();
if (screen)
    QPixmap originalPixmap = screen->grabWindow(0);

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow