I am trying to figure out how to change the background color of one cell, the changing of the actual text and changing the text alignment is also working correctly, but the background color isn't changing. Any thoughts?
{
if(index.column() == _statusIdx)
{
int status = value.toInt();
switch(role)
{
case Qt::DisplayRole:
if(value.isValid())
{
switch(status)
{
case 0:
return tr("");
case 1:
return tr("Uncopied");
case 2:
return tr("Modified");
case 3:
return tr("Copied");
}
}
break;
case Qt::TextAlignmentRole:
return Qt::AlignHCenter | Qt::AlignVCenter;
//case Qt::BackgroundColorRole:
case Qt::BackgroundRole:
switch(status)
{
case 0:
case 1:
// use the default
break;
case 2:
case 3:
}
break;
}
}
return value;
}
QVariant FavoriteSqlModel::data(const QModelIndex &index, int role) const
{
QVariant value = QSqlQueryModel::data(index, role);
if(index.column() == _statusIdx)
{
int status = value.toInt();
switch(role)
{
case Qt::DisplayRole:
if(value.isValid())
{
switch(status)
{
case 0:
return tr("");
case 1:
return tr("Uncopied");
case 2:
return tr("Modified");
case 3:
return tr("Copied");
}
}
break;
case Qt::TextAlignmentRole:
return Qt::AlignHCenter | Qt::AlignVCenter;
//case Qt::BackgroundColorRole:
case Qt::BackgroundRole:
switch(status)
{
case 0:
case 1:
// use the default
break;
case 2:
return QColor(Qt::yellow);
case 3:
return QColor(Qt::darkGreen);
}
break;
}
}
return value;
}
To copy to clipboard, switch view to plain text mode
Bookmarks