
Originally Posted by
jpn
How does a grid fit to a tree??
...unless there are only top level items and root decoration is set to false, which means you have a multi-column list 

Originally Posted by
prakash
Could you please provide me some sample code ?
If you use the custom delegate approach proposed by wysota:
override QItemDelegate:
aint()
{
if (idx.isValid())
{
p->setPen(Qt::DotLine);
p->drawRect(opt.rect);
}
}
void MyItemDelegate::paint(QPainter* p, const QStyleOptionViewItem &opt, const QModelIndex &idx) const
{
QItemDelegate::paint(p, opt, idx);
if (idx.isValid())
{
p->setPen(Qt::DotLine);
p->drawRect(opt.rect);
}
}
To copy to clipboard, switch view to plain text mode
And the another approach, override QTreeView::drawRow()
{
for (int col = 0; col < columnCount(); ++col)
{
if (s.isValid())
{
QRect rect
= visualRect
(s
);
p->setPen(Qt::DotLine);
p->drawRect(rect);
}
}
}
void MyTreeWidget::drawRow(QPainter* p, const QStyleOptionViewItem &opt, const QModelIndex &idx) const
{
QTreeWidget::drawRow(p, opt, idx);
for (int col = 0; col < columnCount(); ++col)
{
QModelIndex s = idx.sibling(idx.row(), col);
if (s.isValid())
{
QRect rect = visualRect(s);
p->setPen(Qt::DotLine);
p->drawRect(rect);
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks