我正在使用QTableView和QStandardItemModel,并尝试着对一行进行颜色标记,使字体仍保持黑色。
我在使用委托类的paint方法:
void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QBrush brush(Qt::red, Qt::SolidPattern);
painter->setBackground(brush);
}
这根本不起作用,而且使得每个单元格内的文本透明。我在这里做错了什么?
[编辑] 我也使用了
painter->fillRect(option.rect,brush);
,但是它使单元格背景和文本颜色相同。
QStandardItem::setData()
函数,使用Qt::FontRole
和Qt::BackgroundColorRole
角色。 - vahanchoDelegate
继承了一些有用的东西吗? - Marek RdrawDisplay()
函数,与fillRect()
一起使用,它似乎可以做到我想要的,即绘制背景并保持文本为黑色。 - ethane