lanz, у меня не работает то, что вы предлагаете... Вот мой код.
#ifndef MYMODEL_H
#define MYMODEL_H
#include <QSqlTableModel>
class MyModel : public QSqlTableModel
{
Q_OBJECT
public:
MyModel(QObject *parent = 0);
QVariant data(const QModelIndex &index,
int role = Qt::DisplayRole) const;
QVariant headerData(int section,
Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
};
#endif // MYMODEL_H
#include <QtSql>
#include "mymodel.h"
MyModel::MyModel(QObject *parent) :
QSqlTableModel(parent)
{
}
QVariant MyModel::data(
const QModelIndex &index, int role) const
{
QVariant value = QSqlTableModel::data(index, role);
switch (role) {
case Qt::BackgroundRole:
if (index.column() == 3)
return QBrush(Qt::green); //ЭТО РАБОТАЕТ
else
return value;
}
return value;
}
QVariant MyModel::headerData(
int section, Qt::Orientation orientation, int role) const
{
QVariant value = QSqlTableModel::headerData(section, orientation, role);
switch (role) {
case Qt::BackgroundRole:
if (section == 2)
return QBrush(Qt::green); //А ЭТО НЕ РАБОТАЕТ
else
return value;
}
return value;
}