Pyside2 5.12 AttributeError:'shiboken2.libshiboken.VoidPtr'对象没有属性'typeInfo'TreeView

时间:2019-01-03 19:25:30

标签: python pyside2

我最近已从PySide2 5.11.2升级到PySide2 5.12。我的TreeView模型在升级之前一直可以使用,但现在由于出现错误而失败, “ AttributeError:'shiboken2.libshiboken.VoidPtr'对象没有属性'typeInfo'”

typeIfo存在于Node的类中,但是以某种方式在pyside2 5.12中没有标识

这是我的代码:

class ABModel(QtCore.QAbstractItemModel):  
    def __init__(self, root, parent=None):
        super(ABModel, self).__init__(parent)
        self._rootNode = root

    def rowCount(self, parent):
        if not parent.isValid():
            parentNode = self._rootNode
        else:
            parentNode = parent.internalPointer()
        return parentNode.childCount()


     def columnCount(self, parent):
        return 8

    def data(self, index, role):
        if not index.isValid():
            return None

        node = index.internalPointer()
        typeInfo = node.typeInfo()

        if role == QtCore.Qt.DisplayRole or role == QtCore.Qt.EditRole:
            if index.column() == 0:
                return node.name()

            if index.column() == 1:
                return typeInfo

    def headerData(self, section, orientation, role):
        if role == QtCore.Qt.DisplayRole:
            if section == 0:
                return "TASKS"
            else:
                return "DATE"


    def flags(self, index):
        return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable 


    def parent(self, index):
        node = self.getNode(index)
        parentNode = node.parent()

        if parentNode == self._rootNode:
            return QtCore.QModelIndex()

        return self.createIndex(parentNode.row(), 0, parentNode)


    def index(self, row, column, parent):
        parentNode = self.getNode(parent)
        childItem = parentNode.child(row)

        if childItem:
            return self.createIndex(row, column, childItem)
        else:
           return QtCore.QModelIndex()


    def getNode(self, index):
        if index.isValid():
            node = index.internalPointer()
            if node:
                return node

        return self._rootNode

class Node(QtCore.QObject):
    def __init__(self, name, parent=None):
        super(Node, self).__init__()
        self._name = name
        self._children = []
        self._parent = parent

        if parent is not None:
            parent.addChild(self)


    def typeInfo(self):
        return "NODE"

    def addChild(self, child):
        self._children.append(child)

    def insertChild(self, position, child):

        if position < 0 or position > len(self._children):
            return False

        self._children.insert(position, child)
        child._parent = self
        return True
    def setName(self, name):
        self._name = name

    def child(self, row):
        return self._children[row]

    def childCount(self):
        return len(self._children)

    def parent(self):
        return self._parent

    def row(self):
        if self._parent is not None:
            return self._parent._children.index(self)

0 个答案:

没有答案