I have my own subclass of QListView and I would like to change the color of an item with index mLastIndex . I tried with
QModelIndex vIndex = model()->index(mLastIndex,0) ;
QMap<int,QVariant> vMap;
vMap.insert(Qt::ForegroundRole, QVariant(QBrush(Qt::red))) ;
model()->setItemData(vIndex, vMap) ;
But it didn't change the color, instead, the item wasn't displayed anymore. Any idea about what was wrong?
model()->setData(vIndex, QBrush(Qt::red), Qt::ForegroundRole);
instead. – BillboardsetItemData()
function returns? – BillboardvMap.insert(Qt::ForegroundRole, QBrush(Qt::red)); model()->setItemData(vIndex, vMap);
? – Billboardemit dataChanged
after setting item data withsetItemData
? – Conformal