Qt-QTreeView绘制单元格
- 只须在自定义的委托类里重写paint函数即可,具体写法如下所示:
1 void ComboBoxDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const 2 { 3 QPen pen; 4 pen.setWidth(1); //设置线的宽度 5 pen.setColor(QColor(176, 196, 222, 255)); //设置线的颜色 6 7 painter->save(); 8 painter->setPen(pen); 9 painter->drawRect(option.rect); //每一个单元格的矩形框 10 painter->restore(); 11 12 QItemDelegate::paint(painter, option, index); //必须调用原有的绘制函数,否则界面显示会异常 13 }
-
效果如图所示: