Get Desktop Screenshot Without Application Window Being Shown
I know how to get a screenshot of the desktop (). But, I want to exclude the window of the application that takes the screenshot.
I tried to hide the window right before taking the screenshot, and show it right after. But this didn't work.
Thanks.
Re: Get Desktop Screenshot Without Application Window Being Shown
What about it "didn't work"?
Re: Get Desktop Screenshot Without Application Window Being Shown
You can try this.
QApplication::desktop()->raise();
QPixmap pixmap(QPixmap::grabWindow(QApplication::desktop()->winId()));
Re: Get Desktop Screenshot Without Application Window Being Shown
This request is exactly what the Screenshot Example does.
On my Linux box if there is no delay between the hide() and the screenshot the KDE window manager may not have faded out the "hidden" window before the screen is grabbed. Turning off KDE desktop effects or introducing a long enough delay (~500 ms) avoids this. I would not be surprised if similar quirks are seen with over window managers. The screen shot example does not allow hiding the window if no delay is selected.
In-a-nutshell version:
Code:
#include <QtGui>
Q_OBJECT
public:
QTimer::singleShot(3000,
this,
SLOT(onButtonClicked
()));
// fake clicking a button after 3 secs }
public slots:
void onButtonClicked() {
hide();
QTimer::singleShot(500,
this,
SLOT(snapshot
()));
// long enough for window manager effects }
void snapshot() {
p.save("screen.png");
show();
QTimer::singleShot(3000,
qApp,
SLOT(quit
()));
// close the app in 3 secs }
};
int main(int argc, char **argv) {
Window w;
w.show();
return app.exec();
}
#include "main.moc"
Re: Get Desktop Screenshot Without Application Window Being Shown
First, thanks all.
But It seems that I chose the wrong approach to achieve my goal.
I wanted to make an application that magnifies the area covered by the application window. My approach was to get a screenshot at the specified rectangle, then scale the image to look magnified. This effect is supposed to work as I drag the window. So, the idea of hiding/showing the application window will not be comfortable.
Is there a method to get the desktop screenshot without the application window, without hiding it?
I feel like I have to get my hands in some window manager/display server work. I hope I am wrong.
Note: I looked at magnifier applications like KMag. But, it doesn't achieve the goal I stated above.
Re: Get Desktop Screenshot Without Application Window Being Shown
I think that to do what you want, you would have to tap into the window compositor itself (e.g. implement your app as a KWin effect plugin) as what you require is obtaining the desktop composition state before your window is rendered and then rendering and compositing the result into the final desktop display.