Results 1 to 2 of 2

Thread: Error while saving large QGraphicsScene as png image using QImage

  1. #1
    Join Date
    Sep 2012
    Pune, India
    Thanked 1 Time in 1 Post
    Qt products

    Question Error while saving large QGraphicsScene as png image using QImage


    I have large QGraphicsScene with large number of graphics object on it.
    I want to export the scene as image (PNG) it is giving following errors:

    Painter::begin: Paint device returned engine == 0, type: 3
    QPainter::setRenderHint: Painter must be active to set rendering hints
    QPainter::save: Painter not active
    QPainter::setClipRect: Painter not active
    QPainter::setWorldTransform: Painter not active
    QPainter::save: Painter not active
    QPainter::setBrushOrigin: Painter not active
    QPainter::restore: Unbalanced save/restore
    QPainter::opacity: Painter not active
    QPainter::worldTransform: Painter not active

    Qt Code:
    1. QImage image(scene->sceneRect().width(), scene->sceneRect().height(), QImage::Format_ARGB4444_Premultiplied);
    2. QPainter painter(&image);
    3. painter.setRenderHint(QPainter::Antialiasing);
    4. scene->render(&painter);
    To copy to clipboard, switch view to plain text mode 
    But this works fine for the small scene with less no of graphics item on it.
    So my queries are-

    1. What does it mean by painter not active?
    2. How to resolve the above problem?
    3. Is it related to scene size and/or no. of graphics items on it?

    It would be very helpful for me, if anyone answer the above queries or give any pointers to investigate the issue further.


  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 721 Times in 711 Posts
    Qt products
    Windows Android

    Default Re: Error while saving large QGraphicsScene as png image using QImage

    How large is the sceneRect? If it is too large and QImage cannot allocate enough memory for it, then the QImage will be null (i.e. not a valid paint device), so the painter cannot paint to it.

    It does not have anything to do with the number of graphics items in the scene, the problem is the number of pixels in the scene (width x height). You may have to apply a scale transform to the items in the scene to get the scene bounding rect smaller.
    Last edited by d_stranz; 4th February 2014 at 16:43.

Similar Threads

  1. Saving a QImage from multiple QGLWidgets
    By Rayven in forum Qt Programming
    Replies: 4
    Last Post: 23rd March 2011, 04:37
  2. Saving QImage
    By thgis in forum Qt Programming
    Replies: 5
    Last Post: 1st November 2010, 09:01
  3. qImage saving to jpg problem
    By sqarpi in forum Qt Programming
    Replies: 9
    Last Post: 1st September 2010, 15:43
  4. QPainter error saving an image from a QGraphicsScene
    By cydside in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2010, 04:53
  5. Saving QGraphicsScene with OpenGL to image
    By elbaschid in forum Qt Programming
    Replies: 1
    Last Post: 12th March 2009, 20:32

Tags for this Thread


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.