Suppose I have QGraphicsPixmapItem
from loaded image which is added to QGraphicsScene
. And suppose I'll add several QGraphicsPolygonItem
's on scene. How I can render a part of the scene as full-size image both with polygons that are not in blank area and save this area as image file.
class ImageView(QtWidgets.QGraphicsView):
def __init__(self, parent):
super(ImageView, self).__init__(parent)
self.setFocus()
self._zoom = 0
self._empty = True
self.scene = QtWidgets.QGraphicsScene(self)
self._image = QGraphicsPixmapItem()
self.scene.addItem(self._image)
self.setScene(self.scene)
# some other actions
foo()
def fitInView(self):
# custom fit in view and scaling
bar()
# some other methods
class MainWindow(QtWidgets.QWidget):
def __init__(self):
self.viewer = ImageView(self)
foo()
def _save_image(self):
# method that I need to implement
pass
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…