Results 1 to 5 of 5

Thread: Image export looks messed up

  1. #1
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Image export looks messed up

    I'm trying to export the contents of my QGraphicsScene to PNG. For some reason I have to maintain the scene's bounding rectangle myself.

    Here's a sample export that should contain a purple ellipse and an orange rectangle on a transparent background:



    Why is the exported image messed up like that? Are there any common symptoms that I should look for in my code?

  2. #2
    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: Image export looks messed up

    How exactly do you export the scene to the image?
    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.


  3. #3
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Image export looks messed up

    Qt Code:
    1. QString filename = QFileDialog::getSaveFileName(this, "Export image", "", "Images (*.png)");
    2. int imgWidth = this->myGraphicsScene->width();
    3. int imgHeight = this->myGraphicsScene->height();
    4. QImage qimg(imgWidth, imgHeight, QImage::Format_ARGB32);
    5. QPainter qpainter;
    6. qpainter.begin(&qimg);
    7. this->myGraphicsScene->render(&qpainter);
    8. qpainter.end();
    9. qimg.save(filename);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    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: Image export looks messed up

    You have to fill your image with transparency first. Otherwise you'll have it initialized with whatever happens to be in the chunk of memory assigned as buffer to your image.
    Qt Code:
    1. qimg.fill(Qt::transparent);
    To copy to clipboard, switch view to plain text mode 
    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.


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

    blooglet (27th February 2011)

  6. #5
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Image export looks messed up

    Yeeha, that works! Thanks!

Similar Threads

  1. messed up umlauts when reading from PostgreSQL
    By majorwoody in forum Newbie
    Replies: 1
    Last Post: 20th January 2011, 21:37
  2. Widgets look messed up
    By lechoo in forum Newbie
    Replies: 0
    Last Post: 1st October 2010, 09:24
  3. export a plot as image
    By giusepped in forum Qwt
    Replies: 0
    Last Post: 16th December 2008, 15:43
  4. Help:Export QGraphicsView to Image File
    By cometyang in forum Qt Programming
    Replies: 5
    Last Post: 27th December 2007, 00:39
  5. Layout messed up
    By larry104 in forum Qt Tools
    Replies: 6
    Last Post: 9th August 2007, 00:09

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.