just overide the data function in your model, it looks like this
Qt Code:
  1. QVariant MyTestModel::data(const QModelIndex &index, int role) const
  2. {
  3. switch(role)
  4. {
  5. case Qt::DisplayRole:
  6. return QVariant(QString(tr("%1")).arg((index.column() + 1) * 1000 + index.row() + 1));
  7. case Qt::BackgroundRole:
  8. switch(index.column() % 3)
  9. {
  10. case 0:
  11. return QVariant(QColor(Qt::red));
  12. case 1:
  13. return QVariant(QColor(Qt::green));
  14. case 2:
  15. return QVariant(QColor(Qt::blue));
  16. default://only to disable warning
  17. return QVariant(QColor(Qt::white));
  18. }
  19.  
  20. break;
  21. default:
  22. return QVariant();
  23. }
  24. }
To copy to clipboard, switch view to plain text mode 

the BackgroundRole for the item's background color
the ForegroundRole for the text color