just overide the data function in your model, it looks like this
{
switch(role)
{
case Qt::DisplayRole:
return QVariant(QString(tr
("%1")).
arg((index.
column() + 1) * 1000 + index.
row() + 1));
case Qt::BackgroundRole:
switch(index.column() % 3)
{
case 0:
case 1:
case 2:
default://only to disable warning
}
break;
default:
}
}
QVariant MyTestModel::data(const QModelIndex &index, int role) const
{
switch(role)
{
case Qt::DisplayRole:
return QVariant(QString(tr("%1")).arg((index.column() + 1) * 1000 + index.row() + 1));
case Qt::BackgroundRole:
switch(index.column() % 3)
{
case 0:
return QVariant(QColor(Qt::red));
case 1:
return QVariant(QColor(Qt::green));
case 2:
return QVariant(QColor(Qt::blue));
default://only to disable warning
return QVariant(QColor(Qt::white));
}
break;
default:
return QVariant();
}
}
To copy to clipboard, switch view to plain text mode
the BackgroundRole for the item's background color
the ForegroundRole for the text color
Bookmarks