I created a list view model by inheriting from QAbstractListModel. I implemented data(const QModelIndex &, int ) to provide the list item background colour (on Qt::BackgroundRole) and item text color (on Qt::ForegroundRole).
It works when I run my application without a stylesheet, but as soon as I apply a stylesheet (using QApplication::setStyleSheet) the text color ends up being wrong. The text color stays the color set in the stylesheet.
I debugged through the model and even though it is returning, for example QBrush(QColor(255, 0, 0)), on the ForegroundRole it never applies to the list view.
Is there something I need to do extra to get my list view model to work correctly when a stylesheet is set for the application?
Correct Answer (from answer by king_nak) [https://stackoverflow.com/a/41673494/1151329]:
I added the following in the style sheet (.qss file) after the original QListView block
QListView[default_style="true"]
{
color : default;
}
In my code I then called
ui.listView->setProperty("default_style", QVariant(true));
It works well with any other QListView being styled by the style sheet, but this one with the 'default_style' property uses the palette set by the widget.