Unsolved How to change multiple cells in a tableview
-
Hi!
I have a model inherited from QAbstractTableModel.
I am trying to make changes to several cells, but when changing data for several cells, only one cell's display changes. How do I get the model to update data?def setData(self, index, value, role=QtCore.Qt.EditRole): if not index.isValid(): return False if index.column() == 1: # if value == False: # self.checked[index.row()] = False # print(111) # print(index.row()) # return True if self.checked[index.row()]: self.checked[index.row()] = False self.idChecked = -1 else: self.checked[index.row()] = True if self.idChecked > -1: self.checked[self.idChecked] = False # self.itemData(self.lastIndex).__setitem__(1,1) # self.setData(self.lastIndex,False, role) # print(self.idChecked) # print( self.checked[self.idChecked]) self.idChecked = index.row() self.signalNeedUpdate.emit() # self.dataChanged().emit(index, index) # self.dataChanged().emit(index, index) # self.beginResetModel() # self.lastIndex = index # self.checked[index.row()] = value # self.dataChanged().emit(index, index) return True return False
-
Replacing models for tableview helps. But there are probably better solutions.
-
I am trying to make changes to several cells, but when changing data for several cells, only one cell's display changes. How do I get the model to update data?
If you are saying you have a
setData()
which alters more than one data item, or not the item indicated by the incomingindex
parameter, then you must emitdataChanged
for the index(es) which have been changed, so that the view knows to update.