This can be done via model's data(). You would subclass QSqlQueryModel and reimplement its data(). Get the data from the base class and add a few checks. When the index is valid and the role is Qt::FontRole, make the font striked out if needed. Notice that there's QFont::setStrikedOut(bool) for that. Also, when the index is valid and the role is Qt::DecorationRole, return a corresponding icon (personal/professional). Otherwise return the value retrieved from the base class. Here's something for you to start with:
QVariant MySqlQueryModel
::data(const QModelIndex
& index,
int role
) const {
if (!index.isValid())
switch (role)
{
case Qt::FontRole:
{
if (value.isValid())
font = qvariant_cast<QFont>(value);
if (taskIsDone)
font.setStrikedOut(true);
}
case Qt::DecorationRole:
{
...
if (professional)
return QVariant::fromValue(professionalIcon
);
else
return QVariant::fromValue(personalIcon
);
}
default:
return value;
}
}
QVariant MySqlQueryModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid())
return QVariant();
QVariant value = QSqlQueryModel::data(index, role);
switch (role)
{
case Qt::FontRole:
{
QFont font;
if (value.isValid())
font = qvariant_cast<QFont>(value);
if (taskIsDone)
font.setStrikedOut(true);
return QVariant::fromValue(font);
}
case Qt::DecorationRole:
{
...
if (professional)
return QVariant::fromValue(professionalIcon);
else
return QVariant::fromValue(personalIcon);
}
default:
return value;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks