Results 1 to 2 of 2

Thread: How to save screenshot?

  1. #1
    Join Date
    Feb 2012
    Posts
    13
    Qt products
    Qt4

    Default How to save screenshot?

    Hi, im on Linux, and Im trying to save a screenshot.
    I read that QPixmap::grabWindow() is deprecated, and that I should use QScreen::grabWindow() instead.
    So I did.
    The problem is: The image is not being saved right, and does not show up the correct part of screen (only 4 parts of screen, upside down and in all kind of ways).

    This ma code.
    Qt Code:
    1. void Widget::on_pushButton_clicked()
    2. {
    3. QScreen *QSCREEN = QGuiApplication::primaryScreen();
    4. QPixmap qpix = QSCREEN->grabWindow(this->winId(), 0, 0, QApplication::desktop()->width(),
    5. QApplication::desktop()->height());
    6. qpix.save("/home/marcus/Bilder/Hello.png");
    7. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to save screenshot?

    Qt Code:
    1. void shootScreen()
    2. {
    3. QPixmap originalPixmap; // clear image for low memory situations
    4.  
    5. originalPixmap = QPixmap::grabWidget(tabWidget->currentWidget()); //<== some widget
    6.  
    7. QString format = "png";
    8.  
    9. QString fileName = "myshot.png";
    10.  
    11. originalPixmap.save(fileName, format.toAscii());
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Screenshot with no show
    By mpi in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2011, 11:12
  2. Screenshot example doesn't work on Mac OSX
    By Damiano in forum Qt Programming
    Replies: 0
    Last Post: 19th January 2011, 11:17
  3. Take a screenshot and convert it to PNG but FAST !
    By fitzy in forum Qt Programming
    Replies: 11
    Last Post: 4th November 2009, 08:20
  4. Take a screenshot of a QGraphicsRectItem
    By yazwas in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2009, 13:14
  5. Screenshot
    By graciano in forum Qt Programming
    Replies: 3
    Last Post: 19th April 2009, 16:32

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.