I made some progress by means of subclassing QSqlTableModel and extending data() function.
{
if (role == Qt::TextColorRole && index.column() == 1)
{
// double d = value.toDouble();
// if(d > 0)
}
return value;
QVariant MySqlTableModel::data(const QModelIndex &index, int role) const
{
QVariant value = QSqlTableModel::data(index, role);
if (role == Qt::TextColorRole && index.column() == 1)
{
// double d = value.toDouble();
// if(d > 0)
return QVariant::fromValue(QColor(Qt::blue));
}
return value;
To copy to clipboard, switch view to plain text mode
After that, I tried to compare value with something else, which will led to paint or not the text. But it doesn't work (commented lines). May I ask some orientation on this issue?
Also I am wondering about the benefits of the alternative approaches.
Thanks for the valuable answers.
Added after 29 minutes:
It seems that the value could be retrieved with
double d = this->record(index.row()).value(index.column()).toDouble();
double d = this->record(index.row()).value(index.column()).toDouble();
To copy to clipboard, switch view to plain text mode
Bookmarks