I have a custom QTableModel
which I'm displaying using QTableView
in PyQt. I have some fields set as checkable, and I want to add check all and check none buttons. I feel there should be a way to cause the setData()
to be called from the code in such a way that the checked state will change as well as the code I have already written in setData()
. Is there in fact a way to do this?
Here is the setData I'm using, as requested:
if role == Qt.CheckStateRole:
row = index.row()
column = index.column()
if row == 0 and column != 0:
self._data.parsingConfiguration['columnEnabled'][column-1] = True if value == Qt.Checked else False
self.dataChanged.emit(self.createIndex(1, column), self.createIndex(len(self._data.data),column))
if column-1 == self._data.parsingConfiguration['groupNumberColumn']:
self.setGroupNumber(self.getFirstEnabledMember())
elif column-1 == self._data.parsingConfiguration['timeStepColumn']:
self.setTimeStep(self.getFirstEnabledMember())
self.emit(SIGNAL("layoutChanged()"))
return True
if column == 0 and row != 0:
self._data.parsingConfiguration['rowEnabled'][row-1] = True if value == Qt.Checked else False
self.dataChanged.emit(self.createIndex(row, 1), self.createIndex(row, self._data.numColumns+1))
return True
return False