ich habe mir meine Klasse von QSqlQueryModel abgeleitet, um ein bischen Übersicht in eine unübersichtliche Tabelle zu bringen.
Code: Alles auswählen
class SqlColorQueryModel : public QSqlQueryModel {
Q_OBJECT
public:
SqlColorQueryModel(QObject *parent=0) : QSqlQueryModel(parent) { QAbstractItemView::SelectRows;};
~SqlColorQueryModel() {};
QVariant data (const QModelIndex &item, int role=Qt::DisplayRole) const
{
if (role==Qt::TextAlignmentRole) {
return Qt::AlignRight;
}
if (item.isValid() &&
item.column()==15 &&
role==Qt::ForegroundRole &&
item.data().toInt()<0) {
return QColor(Qt::red);
}
return QSqlQueryModel::data(item, role);
}
};Code: Alles auswählen
if(item.isValid() &&
item.column()==5 &&
item.data().toString()=="----" &&
role == Qt::BackgroundRole){
return QColor(Qt::red);
}
Kann mir jemand verraten warum? Und wie ichs besser mache?