PDA

View Full Version : The QAbstractItemModel' data method failed to overwrite background



Adknocker
5th February 2019, 12:56
I have a QTreeView which has a stylesheet applied to items with "QTreeView::item{background-color:#F7F7F7}". The view has a custom model and in the data method, I change the background of some specific cells like this :


if (index.column() == 3 && role == Qt::BackgroundColorRole)
{
return QColor("#F4FF81");
}

But this is not working to overwrite the value set in stylesheet. Is there anyone who can tell me what I miss? Thanks!!!

tuli
5th February 2019, 14:06
Stylesheets seem to override and ignore the formatting data coming from the model. See this thread for some suggestions and details:

https://forum.qt.io/topic/95940/model-backgroundrole-overridden-by-style-sheet/11

anda_skoa
5th February 2019, 17:15
Either just extend the model to return the other color for the other columns or is a QIdentityProxyModel to supply the "fall back" background color for cells for which the original model didn't provide any.

Cheers,
_

Adknocker
10th February 2019, 11:37
thanks a lot. seems I cannot use stylesheet then.

Thanks a lot. I would try