'Save part of the scene as an image (not the whole scene)

Saving the (entire) scene as an image is not a problem (see my code) ... but I'd like to save a part of the scene with precise coordinates (and not the whole scene) ... and there I don't know how to go about it, is it possible?, if so, how to do it?, can you help me?

scene_rectangle = self.scene.sceneRect()
                    
self.scene.clearSelection()
                    
img = QImage(QSize(self.scene.sceneRect().width(), self.scene.sceneRect().height()), QImage.Format_ARGB32_Premultiplied)
                    
painter = QPainter(img)

self.scene.render(painter, target=QRectF(self.scene.sceneRect().x(), self.scene.sceneRect().y(), self.scene.sceneRect().width(), self.scene.sceneRect().height()), source=scene_rectangle)
painter.end()
                    
img.save("... path to save ... /image.png")


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source