本文仅供记录,各位如有参考,不胜荣幸
解决之前临时变量销毁导致的程序奔溃,使用成员变量定义
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5 import QtWidgets
from PyQt5 import QtGui
class GraphicsView(QtWidgets.QGraphicsView):
def __init__(self, parent=None):
super(GraphicsView, self).__init__(parent)
self.setGeometry(300, 300, 680, 800)
self.setScene(QtWidgets.QGraphicsScene(self))
self.pixmapItem = (
QtWidgets.QGraphicsPixmapItem()
) # check if everytime you open a new image the old image is still an item
self.scene().addItem(self.pixmapItem)
self._path_item = None
self.img = None
self.filename = ""
def initial_path(self):
self._path = QtGui.QPainterPath