How to create grid line in QTreewidget
Unsolved
General and Desktop
-
Hi
Do you mean like this
-
This is not supported out-of-the box, you have to paint it by your own - either by reimplementing paintEvent() or maybe with a QStyledItemDelegate. But both are not trivial (for you)
-
Hi
It was a treewidget with multiple columns :)maybe easier to see here
anyway, this is a Delegate as @Christian-Ehrlicher talks about.
class GridDelegate : public QStyledItemDelegate { public: explicit GridDelegate(QObject * parent = nullptr) : QStyledItemDelegate(parent) { } void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { painter->setPen(QColor(Qt::black)); // set ink to black painter->drawRect(option.rect); // draw a rect covering cell area QStyledItemDelegate::paint(painter, option, index); // tell it to draw as normally after } };
and you apply it via
ui->treeWidget->setItemDelegate(new GridDelegate);However, this is a very simple example. it just
draws a box on the cell area.
You might want to to be slightly differnt for the the effect you want. -