471
社区成员




如题,QTreeView想在二维表格中显示内容,如果没有数据,表格也能显示网格线,如下截图所示:
我尝试通过代理的方式去绘制网格线,但是还是失败了,在没有数据的时候,它没有网格线。具体代码如下:
void GridLineDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QPen pen;
pen.setWidth(1); //线的宽度
pen.setColor(QColor(190, 190, 190, 255)); //线的颜色
painter->save();
painter->setPen(pen);
painter->drawRect(option.rect); //单元格矩形框
painter->restore();
QStyledItemDelegate::paint(painter, option, index); //调用绘制函数
}
各位大佬们,不知道你们有没有办法解决这个问题呢?欢迎大佬们指点一二,小弟感激不尽!!