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);
}