Issue
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?
Solution
This looks like a bug in PySide, as connect
should accept any callable (the example code works correctly in PyQt4).
As a workaround, try wrapping QStandardItem
methods in a lambda:
signalSource.availabilityChanged.connect(
lambda enable: categoryItem.setEnabled(enable))
EDIT
To connect the items in a loop, use a default argument, like this:
for button in buttonList:
item = QStandardItem("Test")
...
button.toggled.connect(
lambda enable, item=item: item.setEnabled(enable))
Answered By - ekhumoro
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.