Unsolved QTableView look alike QTreeView
-
Hello,
is it possible to make QTableView look alike QTreeView?
-
Why not use QTreeView?! it has support for multiple columns. if you want it to display only the first level items then subclass QIdentityProxyModel and reimplement the flag and hasChildren methods:
class TreeToTableProxy : public QIdentityProxyModel{ Q_OBJECT public: explicit TreeToTableProxy(QObject* parent = nullptr) : QIdentityProxyModel(parent){} virtual ~TreeToTableProxy() = default; virtual Qt::ItemFlags flags(const QModelIndex &index) const override{ const Qt::ItemFlags baseflag = QIdentityProxyModel::flag(); if(index.isvalid()) return baseflag | Qt::ItemNeverHasChildren; return baseflag; } virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const override { return !parent.isvalid(); } }