Hi all,

I developed a GUI application using PyQt which comport a QGraphicsView. In this QGraphicsView I have a QGraphicsScene with a lot of items (more than 10'000): polygons, rectangles, texts, etc.

How can I save it as an image like it appears on the screen (.png for example)? I couldn't find any example of this. Should I use QImage or something like this?

Thank you


Recommended Answers

QImage has a save function. See "Reading and Writing Image Files" here

Jump to Post

All 4 Replies

QImage has a save function. See "Reading and Writing Image Files" here

Hi Woooee, thanks for you answer!

I saw that I could save a QImage, but my problem is: how to transfer all my items into a QImage from my qgraphicsview or qgraphicsscene.

Any idea?



I would try render first, but I have never tried it. From the docs at http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qgraphicsview.html

QGraphicsView.render (self, QPainter, QRectF target = QRectF(), QRect source = QRect(), Qt.AspectRatioMode mode = Qt.KeepAspectRatio)

Renders the source rect, which is in view coordinates, from the scene into target, which is in paint device coordinates, using painter. This function is useful for capturing the contents of the view onto a paint device, such as a QImage (e.g., to take a screenshot), or for printing to QPrinter.

You could also try the PyQt Forum

It works perfectly with the render method of QGraphicsScene.

Thank you very much Woooee, it helped me very much!

See you


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.