如何創建一個擴展QGraphicsItem的類來定義一種新的Item?用pyqt擴展QGraphicsItem
我試圖做到這一點
#!/usr/bin/python
import sys
from PyQt4 import QtGui
class Node(QtGui.QGraphicsItem):
def __init__(self, parent = 0):
self.setFlag(QtGui.QGraphicsItem.ItemIsMovable)
app = QtGui.QApplication(sys.argv)
scene = QtGui.QGraphicsScene()
scene.addText("test")
scene.addItem(Node())
view = QtGui.QGraphicsView(scene)
view.show()
sys.exit(app.exec_())
,但我得到這個錯誤
Traceback (most recent call last):
File "primo.py", line 15, in <module>
scene.addItem(Node())
File "primo.py", line 8, in __init__
self.setFlag(QtGui.QGraphicsItem.ItemIsMovable)
RuntimeError: underlying C/C++ object has been deleted
我在做什麼錯?我不能叫節點的初始化方法中的QGraphicsItem構造,因爲的QGraphicsItem它是一個抽象類