I have this QTableView with a custom model and a delegate, how do I change the background color of a cell after editing it?
should I do this in the setModelData() ?
index.model.setData(index, QVariant(True),Qt.UserRole)
and then in the data() # model calling itself?
if role == Qt.BackgroundColorRole: if index.model().data(index,Qt.UserRole).toBool(): return QVariant(QColor(Qt.darkBlue))
and in the setData() model, I have no code:
if role==Qt.UserRole: ....
What is the right way to do this?
edit: Here is my setData() method in the user model
def setData(self, index, value, role=Qt.EditRole): if index.isValid() and 0 <= index.row() < len(self.particles): particle = self.particles[index.row()] column = index.column() if column == ID: value,ok= value.toInt() if ok: particle.id =value elif column == CYCLEIDANDNAME: cycleId,cycleName= value.toString().split(' ') particle.cycleId =cycleId # also need to set cycleName for name in self.cycleNames: if name.endsWith(cycleName): particle.cycleFrameNormalized=particle.cycleName = name break elif column == CYCLEFRAME: value,ok= value.toInt() if ok: print 'set new val to :',value particle.cycleFrame =value # self.setData(index,QVariant(QColor(Qt.red)),Qt.BackgroundRole) elif column == CLASSID: value,ok= value.toInt() if ok: particle.classId =value elif column == VARIATIONID: value,ok= value.toInt() if ok: particle.variationId =value self.emit(SIGNAL("dataChanged(QModelIndex,QModelIndex)"), index, index) return True return False
Sorry, still has no idea, I will insert the full code from the gui quick development example: I posted my code here http://pastebin.com/ShgRRMcY
How can I change the code to change the background color of the cell after editing the cell?