重写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);
}
实现效果如下:

该博客介绍了如何重写QTreeView的drawRow方法,以实现自定义的行绘制效果。通过保存和恢复画家状态,设置灰色边框并调用基类的drawRow方法,实现了在标准绘制基础上的增强。示例代码展示了具体的实现细节。
721

被折叠的 条评论
为什么被折叠?



