Results 1 to 6 of 6

Thread: Get Desktop Screenshot Without Application Window Being Shown

  1. #1
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Get Desktop Screenshot Without Application Window Being Shown

    I know how to get a screenshot of the desktop (
    Qt Code:
    1. QPixmap::grabWindow(QApplication::desktop()->winId())
    To copy to clipboard, switch view to plain text mode 
    ). 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.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Get Desktop Screenshot Without Application Window Being Shown

    What about it "didn't work"?

  3. #3
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Get Desktop Screenshot Without Application Window Being Shown

    You can try this.
    QApplication::desktop()->raise();
    QPixmap pixmap(QPixmap::grabWindow(QApplication::desktop()->winId()));

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default 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:
    Qt Code:
    1. #include <QtGui>
    2. class Window: public QWidget {
    3. Q_OBJECT
    4. public:
    5. explicit Window(QWidget *p = 0): QWidget(p) {
    6. QTimer::singleShot(3000, this, SLOT(onButtonClicked())); // fake clicking a button after 3 secs
    7. }
    8. public slots:
    9. void onButtonClicked() {
    10. hide();
    11. QTimer::singleShot(500, this, SLOT(snapshot())); // long enough for window manager effects
    12. }
    13. void snapshot() {
    14. QPixmap p = QPixmap::grabWindow(QApplication::desktop()->winId());
    15. p.save("screen.png");
    16. show();
    17.  
    18. QTimer::singleShot(3000, qApp, SLOT(quit())); // close the app in 3 secs
    19. }
    20. };
    21.  
    22. int main(int argc, char **argv) {
    23. QApplication app(argc, argv);
    24. Window w;
    25. w.show();
    26. return app.exec();
    27. }
    28. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to ChrisW67 for this useful post:

    INeedADollar (28th March 2020)

  6. #5
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    personk (10th August 2013)

Similar Threads

  1. Replies: 0
    Last Post: 26th April 2011, 12:32
  2. Don't redraw desktop, use a screenshot instead.
    By danciac in forum Qt Programming
    Replies: 2
    Last Post: 8th September 2010, 11:40
  3. QT Desktop Screenshot not working
    By harleyskater in forum Qt Programming
    Replies: 11
    Last Post: 27th June 2010, 04:25
  4. Replies: 5
    Last Post: 31st January 2009, 07:36

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.