回复:
Qt::BackgroundRole改成Qt::ForegroundRole,就是文字颜色.(0,5)单元格就是index.column()==5&&index.row()==0
subclass你的Model,重载data、setData函数,以data()为例:
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();
}
}