Can I attach objects to QListWidgetItems in PyQt?
-
20-02-2021 - |
문제
Is it possible to set/get a object for an item in a QListWidget the same way you set/get the text of the item?
해결책
There's QListWidgetItem.setData:
item = QListWidgetItem('Text', parent)
data = ('foo', 'bar', [1, 2, 3])
item.setData(Qt.UserRole, data)
...
# QVariant version 1 API (python2 default)
print item.data(Qt.UserRole).toPyObject()
# QVariant version 2 API (python3 default)
print item.data(Qt.UserRole)
제휴하지 않습니다 StackOverflow