必须重写QItemDelegate的paint方法。
xxxx.h
class Delegate :publicQItemDelegate
{
Q_OBJECT
public:
Delegate(QWidget*parent =0):QItemDelegate(parent){}
void paint(QPainter*painter, constQStyleOptionViewItem&option,
constQModelIndex&index)const;
};
xxxx.cpp
table->setItemDelegate(new Delegate);
void Delegate::paint(QPainter*painter, constQStyleOptionViewItem&option,
constQModelIndex&index)const
{
if(index.column()== 2)
painter->fillRect(option.rect, option.palette.highlight());
QItemDelegate::paint(painter, option, index);
}