Qt Model/View view单元格值改变其相应的背景颜色也变

只需要在

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);
  }
 }


 

猜你喜欢

转载自blog.csdn.net/hlday6/article/details/39367197