只需要在
Model类中的 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 方法中进行判断 设置颜色
if (Qt::BackgroundColorRole == role)
{
if(index.column() == 0)
{
return QColor(255,255,225);
}
else if (index.column() == 1)
{
//当原始值与现值不一样时
if(dDensity != dSrcDensity)
{
return QColor(255,255,128);
}
return QColor(255,255,255);
}
}