I want to enable/disable a checkable item in a QTreeWidget, when a specific signal is sent.
The following code dows not work:
model = QStandardItemModel()
view = QTreeView()
view.setModel(model)
rootItem = QStandardItem()
rootItem = model.invisibleRootItem()
categoryItem = QStandardItem(item)
categoryItem.setCheckable(True)
rootItem.appendRow(categoryItem)
signalSource.availabilityChanged.connect(categoryItem.setEnabled)
It produces the error:
TypeError: unhashable type: 'PySide.QtGui.QStandardItem'
Is there a solution for changing the state or data of a QStandardItem via signal/slot?
This looks like a bug in PySide, as
connectshould accept any callable (the example code works correctly in PyQt4).As a workaround, try wrapping
QStandardItemmethods in a lambda:EDIT
To connect the items in a loop, use a default argument, like this: