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?
Thanks
For Qt the way you "take a screenshot of a specific window" is to:
Have a look at Screenshot example
In short:
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.Also look at
WindowFromPoint
andEnumChildWindows
. The latter could allow you to prompt the user to disambiguate if you had multiple windows with the same title.Although this has already been answered, just for the sake of completeness, I'll add to Trevor Boyd Smith's post (see above) a code-snippet example:
Look at QDesktopWidget class. It's inherited from QWidget so there is literally no problem of taking screenshot: