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. How to Choose between QtreeView(QAbstractItemModel) vs QTreeWidget
QtWS25 Last Chance

How to Choose between QtreeView(QAbstractItemModel) vs QTreeWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 11.5k 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    I have application in which currently the data displayed in is in multiple table format

    Current
    Table1 : header (Report1)
    column1 column2 column3
    A 3 4
    B 3 4
    C 3 4

    Table 2 : Report2
    column0 column1 column3
    E 3 3
    F 3 4
    G 3 4

    The New View has be in Tree format
    +Report1 (21)
    A (7)
    B (7)
    C (7)
    + Report2(21)
    E (7)
    F(7)
    G (7)

    What should be considered for New View QTreeView or QTreeWidget (with QAbstractItemModel) item
    
    1 Reply Last reply
    0
    • A Offline
      A Offline
      aliks-os
      wrote on last edited by
      #2

      It all depends on your application. If you will be using the data stored in the model and not only displayed in the tree, you should use the QTreeView (And model). If you want to display data only, that is better to use the QTreeWidget

      1 Reply Last reply
      1
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on last edited by
        #3

        Currently the Table view is in model format . but the model stores data for table view but do coverting it into tree view will require another model creation

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          Qt Enthusiast
          wrote on last edited by
          #4

          If I have a application that will can add upton maximum 500 elements IN QtreeWidget will it lead to performance issue in QtreeWidget

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

            What will they contain ? Will you be doing any processing on them ? Special visualization ?

            500 is not necessarily a huge amount of items.

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

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              Qt Enthusiast
              wrote on last edited by
              #6

              They will contain string . The string , if select the row in QtreeWidget on left , then it should fill the QTableView at the right

              1 Reply Last reply
              0
              • ToniyT Offline
                ToniyT Offline
                Toniy
                wrote on last edited by Toniy
                #7

                QTreeWidget, QTableWidget, QListWidget are just convenience classes (for quick start of sorts. Documentation advises to use Model-View approach) which use Model-View architecture on low levels in any case. Meanwhile QTreeView-QAbstractItemModel approach gives you more flexibility during application developing despite it can look difficult first time.

                Let's consider an example like this: you displayed your information with QTreeWidget. Everything was looking good, but later your boss (or customer) asked you to show data as a table. You did similar steps for filling your newly created QTableWidget with data (QTreeWidget was deleted meanwhile so you had lost your previous results) and everything seems fine again. But later your boss asked you to show data both as a tree and as a table in different places of application. So you need to create tree widget from scratch again. Moreover you have duplicated data now so if it changes you need to be aware that you apply these changes to both widgets.

                With Model-View approach your actions for that scenario could be these: fill model with data and show it like tree, then just change QTreeView to QTableView without model refilling and then just create another QTreeView and connect it to the same model. In that case you need to modify data once in model, and all connected views (maybe one, maybe two, maybe ten) will know about it and modify displayed content. So use Model-View approach everywhere instead of convenience widgets if you want to maintain your applications without bloody tears :-)

                1 Reply Last reply
                2
                • Q Offline
                  Q Offline
                  Qt Enthusiast
                  wrote on last edited by
                  #8

                  I want to hide headers in QtreeWidget . Can someone guide me how to do it.

                  Also I have a QtreeView with multiple parent items . Can some one guide me a sample example for the same . How to create a QtreeView with multiple parents

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

                    QTreeWidget's detailed documentation shows how to add one top level item. Adding several uses the exact same technique.

                    As for hiding the headers. Just call hide on both horizontal and vertical header views.

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

                    1 Reply Last reply
                    0
                    • Q Offline
                      Q Offline
                      Qt Enthusiast
                      wrote on last edited by
                      #10

                      @Qt-Enthusiast said:

                      Just wanted to clarify , I am asking for QtreeView with a custom model and multiple items can be as root node abd can have children

                      A
                      --- B

                      • C
                        D
                        -- E
                        -F

                      here A and D are at same level and B C and children of A and E and F are children D

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

                        Take a look at the documentation of QStandardItemModel

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

                        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