-1

How to create png image from QGraphicsScene in one click on a button , i have a gui and a button named to_png so I want to create a png picture of my QGraphicsScene when I click on this button

  • Does this answer your question? [Saving a QGraphicsScene to Svg changes scaling](https://stackoverflow.com/questions/34183996/saving-a-qgraphicsscene-to-svg-changes-scaling) It is not quite a duplicate, but the question already contains code you can build off of. – Botje Mar 30 '20 at 11:51

1 Answers1

1

Using QGraphicsScene::render() allows you to render the scene to a QPainter. Therefore, you can just render it into a QImage. This is actually mentioned in the documentation of QGraphicsScene::render().

Untested example:

QImage image;
QPainter painter(&image);
painter.setRenderHint(QPainter::Antialiasing);
scene.render(&painter);
image.save("screenshot.png")
Joel Bodenmann
  • 2,152
  • 2
  • 17
  • 44