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{
    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();
    return baseflag  | Qt::ItemNeverHasChildren;
    return baseflag;
    virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const override {
    return !parent.isvalid();

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.