0

I have a QGraphicScene object that I can save to a PNG file just fine as long as I haven't made any modifications like a scroll or a zoom on the item. After performing a scroll or a zoom, the saved image becomes small with a lot of transparent pixels filling in the desired dimensions. I'm thinking it has to do with needing to render the visible region of the QGraphicsView to the QImage that gets saved but I'm having trouble figuring this out.

Below is some of my code:

void myClass::saveSceneAsPNGImage(QString path, int width)
{
    Scene->clearSelection();

    double scaleFactor = (width / Scene->sceneRect().size().width());

    QImage image(Scene->sceneRect().size().width() * scaleFactor, 
        Scene->sceneRect().size().height() * scaleFactor, 
        QImage::Format_ARGB32);

    QPainter painter(&image);
    painter.setRenderHint(QPainter::Antialiasing);
    Scene->render(&painter);
    image.save(path);
}
roundtheworld
  • 2,651
  • 4
  • 32
  • 51
  • Can you explain what result you would like to have at the end? – dgrat Feb 18 '14 at 18:58
  • I'd like to have the scene that I can see in my GUI (the way it's scrolled and zoomed) saved to a PNG file with dimensions that may vary from the original size of the scene. – roundtheworld Feb 18 '14 at 19:00
  • 1
    Maybe you can upload the two pictures, with and without zoom. – dgrat Feb 19 '14 at 09:22

0 Answers0