I'm attempting to apply the principle outlined in the following post, but for the CheckStateRole of my model (which is defined both in the data/setData methods of my model):
how can i achieve to update multiple rows in a qtableview
However, I realized checking/unchecking a column (in my case column 0), doesn't seem to call commitData at all.
Here's the code snippet:
class MyTableView(QtGui.QTableView):
"""
View that will set all selected rows to the current CheckedState.
"""
def __init__(self, parent=None):
super(MyTableView, self).__init__(parent)
def commitData(self, editor):
# this method is not called when a user checks/unchecks an item
super(MyTableView, self).commitData(editor)
model = self.currentIndex().model()
current_row, current_column = self.currentIndex().row(), 0
value = model.data(model.index(current_row, current_column), QtCore.Qt.CheckStateRole)
for row in self.selectionModel().selectedRows(0):
if row != current_row:
index = model.index(row, current_column)
model.setData(index, value, QtCore.Qt.CheckStateRole)
How can achieve this for checkboxes in a QTableView using a QAbstractTableModel?
Internally, how is the checkBox handled? Is it not considered a delegate which calls commitData?
Aucun commentaire:
Enregistrer un commentaire