PySide6 中 QVariant 的替代品是什么?

问题描述 投票:0回答:1

正如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"
python pyside
1个回答
0
投票

尝试“任何”。

from typing import Any
© www.soinside.com 2019 - 2024. All rights reserved.