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. QTreeView vs QTableView
Forum Updated to NodeBB v4.3 + New Features

QTreeView vs QTableView

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 2.4k Views 2 Watching
  • 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.
  • JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #1

    Qt5. I have inherited a large project, which works. It has a lot of "table views" in various places. There are no comments/explanations :)

    By "table views" I mean your standard "show-rows-and-columns" from the model. About half the time it uses a QTableView, which is what I would have picked. However, the other half of the time it uses a QTreeView (with setRootIsDecorated(False)). These seem to have things like header columns etc., just like in a QTableView.

    Could someone explain conceptually why/what's going on here? Why would you pick a QTreeView rather than a QTableView for displaying a rows & columns table? (The QTreeViews do not have a "hierarchical" structure, just flat rows/columns, so that's not why.) I need to understand this before I can figure what I want to do.

    If it makes any difference, the origins of the code are way back in Qt4/years ago. Grasping at a straw, was QTreeView a better choice over QTableView years ago?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      A QTreeView is meant to show hierarchical models so you have to check the models used underneath to see what makes more sense to use.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      JonBJ 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        A QTreeView is meant to show hierarchical models so you have to check the models used underneath to see what makes more sense to use.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @SGaist
        Yes, that is what I would have expected. But I'm saying: these QTreeViews just do not have any hierarchical model, they have the same flat row-column (e.g. from a straightforward SQL SELECT * FROM table) as the QTableViews have. That's why I was asking what the reason might have been for the choice?

        Assuming what you say is indeed true, and I can check & confirm the QTableViews are only presenting a flat model view, my thought is to change all the QTreeViews over to QTableViews. For one I like consistency, and for another I'm wanting to put into some major sub-classing facilities for all of these tables, so starting from the same base class is going to make my life easier. What do you think?

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

          I did it myself in the past. The reason has always been visual style.
          Sometimes the default layout and appearance of QTreeView is more appealing than QTableView. nothing major

          "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

          JonBJ 1 Reply Last reply
          3
          • VRoninV VRonin

            I did it myself in the past. The reason has always been visual style.
            Sometimes the default layout and appearance of QTreeView is more appealing than QTableView. nothing major

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @VRonin
            Brill. Just what I wanted to hear. I am launching into changing all the QTreeViews over to QtableViews, before then doing work on them all.

            Thank you, Happy Xmas :)

            1 Reply Last reply
            0

            • Login

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