QListView add item text customization
does anybody know how to set text color for new added item into data model?
My code looks like:
myModel->insertRows(0, 1); QModelIndex index = myModel->index(0); this->m_logModel->setData(index, log); //this works fine !!! QBrush yellow; yellow.setColor(Qt::yellow); this->m_logModel->setData(index, yellow, Qt::TextColorRole); ///this not !!! text color is still black...
What is m_logModel, what is myModel?
Your data model may or may not implement some roles.
The QAbstractItemModel class implementation does nothing and returns false.
It is a good idea to check what setData returns.
First of all, as mentioned in the docs,
Qt::TextColorRoleis obsolete and you should not use it. Use
Second, as mentioned by @alex_malyu, it depends on the model whether or not it implements that. QStandardItemModel for example will, but your custom model might not.
So the question is what is your model class.