How to make selected checkbox Item color to Green in QT?
how to make selected items turn into green?
QVariant DomModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
DomItem *item = static_cast<DomItem*>(index.internalPointer());
const QDomNode node = item->node();
if ( role == Qt::CheckStateRole && (index.column() == 0) && hasChildren(index) )
{
return static_cast< int >( item->isChecked() ? Qt::Checked : Qt::Unchecked );
}
if (role == Qt::FontRole && item->isChecked()) {
QFont font;
font.setBold(true);
return font;
}
if (role != Qt::DisplayRole)
return QVariant();
switch (index.column()) {
case 0:
return node.nodeName();
case 1:
{
const QDomNamedNodeMap attributeMap = node.attributes();
QStringList attributes;
for (int i = 0; i < attributeMap.count(); ++i) {
QDomNode attribute = attributeMap.item(i);
attributes << attribute.nodeName() + "=\""
+ attribute.nodeValue() + '"';
}
return attributes.join(' ');
}
case 2:
return node.nodeValue().split('\n').join(' ');
default:
开发者_开发百科 break;
}
return item->data(index.column());
}
In the role I have done Items which is selected to be Bold when checked, But how change that fonts color to green which is checked?
Please Look at this Image:
精彩评论