我目前正在尝试使用Python和QT为Maya(3D应用程序)创建一些工具。
到目前为止,我相处得很好,但是现在遇到了一些问题,使我无法理解继承。我创建了QListWidgetItem的子类以添加一些自定义逻辑,并希望在以后遍历左侧QListWidget时访问此逻辑。
# Widget to get displayed inside myQListWidget
class BaseModule(QtWidgets.QListWidgetItem):
def __init__(self,name):
super(BaseModule, self).__init__(parent=parent)
self.setText(name)
self.name = name
def BuildSkeleton(self):
# Do some magic in here
window = belt.TWToolbelt()
rootModule = BaseModule(name='Root')
window.ui.AllModules.addItem(rootModule)
model = window.ui.ActiveModules.model()
model.rowsInserted.connect(lambda *_:drop(window))
# function, which get`s executed after a drag&drop action
def drop(window):
items = []
for index in xrange(window.ui.ActiveModules.count()):
items.append(window.ui.ActiveModules.item(index))
for item in items:
# iterating over all Active Modes on the left to execute my custom logic
# as item is a QtWidget.QListWidgetItem and the fucntion is only existing
# in it`s child class BaseModule I would like to know, how I can access or cast from a
# ParentClass to it`s child class, so I can execute my function
item.BuildSkeleton()
该代码出现以下错误:
AttributeError: 'PySide2.QtWidgets.QListWidgetItem' object has no attribute 'BuildSkeleton'
希望您能帮助我。
提前谢谢