Just a sidenote - from a usability point of view, in a majority of cases you probably don't want to paint the entire background.
Screenshot: 2015-09-09 13_37_16-voima - Forceproof Analyst.png
In many cases, using a Qt:: DecorationRole is more aesthetic and less obtrusive than filling the entire cell background. The text is still readable; you don't have to think about the contrast between changed foreground and background colours, since DecorationRole only paints a small rectangle of the color you selected, inside the cell.
{
int column=index.column();
if((role==Qt::DecorationRole)){
if(column==firstVisibleColumnIndex){
// figure out correct color for current row here
}
}
}
QVariant MyModel::data(const QModelIndex &index, int role) const
{
int column=index.column();
if((role==Qt::DecorationRole)){
if(column==firstVisibleColumnIndex){
// figure out correct color for current row here
return QColor(100,255,255);
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks