Issue
How can I test whether an item is checkable in a QTreeview in python/pyside?
def set_selected_shots(self, state=None):
checkstate = QtCore.Qt.Checked if state else QtCore.Qt.Unchecked
selected_rows = self.ui_shots.selectionModel().selectedRows()
for idx in selected_rows:
model = idx.model()
Solution
If you are using QStandardItemModel
then you must use the itemFromIndex()
method that if you provide the index returns the item, and then check the state with the checkState()
method:
selected_rows = self.ui_shots.selectionModel().selectedRows()
for idx in selected_rows:
item = idx.model().itemFromIndex(idx)
if item.isCheckable():
if item.checkState() == Qt.Checked:
print("checked")
else:
print("unchecked")
Answered By - eyllanesc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.