Your code simply clears all the data in the model and leaves only the value for Qt::ForegroundRole
, since your map contains only the new value.
Do it like this (this will work for most data models, not just the standard):
QModelIndex vIndex = model()->index(mLastIndex,0); model->setData(vIndex, QBrush(Qt::red), Qt::ForegroundRole);
Or by correcting your code:
QModelIndex vIndex = model()->index(mLastIndex,0) ; QMap<int,QVariant> vMap = model()->itemData(vIndex); vMap.insert(Qt::ForegroundRole, QVariant(QBrush(Qt::red))) ; model()->setItemData(vIndex, vMap) ;
source share