重写QTreeView的drawRow方法。
void MyTreeView::drawRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
painter->save();
painter->setPen(QColor("gray"));
painter->drawRect(QRect(option.rect.topLeft(), QSize(option.rect.width(), option.rect.height())));
painter->restore();
QTreeView::drawRow(painter, option, index);
}
实现效果如下: