I don't understand what you mean by cash the value ?
A simple data() function to deal with background color wold be for example like this:
{
if(value2.toString() == "" && role == Qt::BackgroundRole) { // if the column 2 on the same row is blank we set the color
}
return value;
}
QVariant CustomSqlModel::data(const QModelIndex &index, int role) const
{
const QAbstractItemModel * model = index.model();
QModelIndex index2 = model->index(index.row(), 1, QModelIndex()); // position 1 on current row
QVariant value2 = QSqlQueryModel::data(index2, Qt::DisplayRole);
if(value2.toString() == "" && role == Qt::BackgroundRole) { // if the column 2 on the same row is blank we set the color
return QVariant(QColor(Qt::yellow));
}
QVariant value = QSqlQueryModel::data(index, role);
return value;
}
To copy to clipboard, switch view to plain text mode
The code is called on every cell, so every cell on the row that has a blank column 2 will be painted - because this if is true on all cell on that row
The faster way would be to have a list of what needs to be updated and the indexes saved - and then call a function that goes in to only the selected rows and repaints only those cell that needs extra features / colors etc. This function must be automatically triggered after the view calls the data function on all cells every time it does that.
Any ideas ?
Or if I try to ask a more precise question : where can i intercept the code that fires the data() function ?? so that I can add a function call to a function that only selct spesific cells to pain over again... hmmm dont know if im makins sence or not sorry.
Bookmarks