Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableView look alike QTreeView
Forum Updated to NodeBB v4.3 + New Features

QTableView look alike QTreeView

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 503 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • michalt38M Offline
    michalt38M Offline
    michalt38
    wrote on last edited by michalt38
    #1

    Hello,

    is it possible to make QTableView look alike QTreeView?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      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();
      }
      }
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved