QVariant MyTableModel::data(const QModelIndex &index, int role) const {
if (role == Qt::ForegroundRole && index.column() == 1) { // notice that Qt::TextColorRole is deprecated
QVariant value = QSqlTableModel::data(index, Qt::DisplayRole);
QVariant value = index.data(); // the data is in DisplayRole
double d = value.toDouble();
if(d > 0)
return Qt::blue; //QVariant::fromValue(QColor(Qt::blue));
}
return QSqlTableModel::data(index, role); // forward everthing else to the base class
}
Edit: Changed line 3 above. Haven't used Qt in a while. The old code does work.