正如doc所说,
QVariant
在Python中被删除了。然而,在某些情况下,我仍然需要QVariant
。
class TreeNode(QObject):
dataChanged = Signal(object, int) # here
def __init__(self, parent = None):
super().__init__(parent)
self._itemData = {}
self._childNodes = []
def setData(self, value, role=Qt.DisplayRole):
self._itemData[role] = value
self.dataChanged.emit(value, role)
@Property(object, fset=setData, notify=dataChanged) # here
def data(self, role=Qt.DisplayRole):
return self._itemData.get(role)
在上面的代码片段中,我必须为
QVariant
和 Signal
指定 Property
。如果我使用对象代替,它会显示
Invalid property assignment: unsupported type "PySide::PyObjectWrapper"
尝试“任何”。
from typing import Any