Treeview with grid lines
-
I have a custom QSortFilterProxyModel with its source model set to the QFileSystemModel displayed via a QTreeView. Is it possible for the QTreeView to show gridlines vertically and horizontally? If so, can you provide an example. Thanks!
-
Hi
You can create a delegate for example :-.h
@class TreeViewDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit TreeViewDelegate(QObject *parent = 0);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;};@
.cpp
@TreeViewDelegate::TreeViewDelegate(QObject *parent) :
QStyledItemDelegate(parent)
{}
void TreeViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyledItemDelegate::paint(painter,option,index);QPen pen; pen.setWidth(1); painter->setPen(pen); painter->drawRect(option.rect);
}@
then you can set the the delegate to the treeView
@ui->treeView->setItemDelagate(treeDelegate);@