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. Use QStandardItemModel with QTreeView

Use QStandardItemModel with QTreeView

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 7 Posters 3.6k 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.
  • R Offline
    R Offline
    rmam
    wrote on last edited by
    #1

    Does anyone know if QStandardItemModel can be used to present a tree view in QTreeView? If so, are there any minimal working examples that showcase how to get a working tree view?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      https://doc.qt.io/qt-5/qstandarditemmodel.html#details - there is a short example on how to build a tree, so yes it's possible to use it in a QTreeView.
      See also https://doc.qt.io/qt-5/qstandarditem.html#appendRow and https://doc.qt.io/qt-5/qstandarditem.html#appendRow-1

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      A 1 Reply Last reply
      3
      • Christian EhrlicherC Christian Ehrlicher

        https://doc.qt.io/qt-5/qstandarditemmodel.html#details - there is a short example on how to build a tree, so yes it's possible to use it in a QTreeView.
        See also https://doc.qt.io/qt-5/qstandarditem.html#appendRow and https://doc.qt.io/qt-5/qstandarditem.html#appendRow-1

        A Offline
        A Offline
        Alexey Serebryakov
        wrote on last edited by
        #3

        @Christian-Ehrlicher so bad incomplete example. :-(

        SGaistS Christian EhrlicherC 2 Replies Last reply
        0
        • A Alexey Serebryakov

          @Christian-Ehrlicher so bad incomplete example. :-(

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Alexey-Serebryakov said in Use QStandardItemModel with QTreeView:

          @Christian-Ehrlicher so bad incomplete example. :-(

          There's a complete example linked in that documentation.

          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
          1
          • A Alexey Serebryakov

            @Christian-Ehrlicher so bad incomplete example. :-(

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Alexey-Serebryakov In which case? There a tree is build up exactly what you requested. There is also a link to a more complete example below: https://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            A 1 Reply Last reply
            1
            • Christian EhrlicherC Christian Ehrlicher

              @Alexey-Serebryakov In which case? There a tree is build up exactly what you requested. There is also a link to a more complete example below: https://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html

              A Offline
              A Offline
              Alexey Serebryakov
              wrote on last edited by Alexey Serebryakov
              #6

              @Christian-Ehrlicher so bad and old example... Also I cant find a good simple example for my task.

              JonBJ Christian EhrlicherC 2 Replies Last reply
              -1
              • A Alexey Serebryakov

                @Christian-Ehrlicher so bad and old example... Also I cant find a good simple example for my task.

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

                @Alexey-Serebryakov
                Googling for QStandardItemModel QTreeView comes up with a number of other hits, have you looked through them to see if one fits you better

                1 Reply Last reply
                0
                • A Alexey Serebryakov

                  @Christian-Ehrlicher so bad and old example... Also I cant find a good simple example for my task.

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @Alexey-Serebryakov said in Use QStandardItemModel with QTreeView:

                  so bad and old example.

                  Sorry but this example is exactly what you want, it doesn't matter when the code was written. You're just to lazy to try to understand it.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  A 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    @Alexey-Serebryakov said in Use QStandardItemModel with QTreeView:

                    so bad and old example.

                    Sorry but this example is exactly what you want, it doesn't matter when the code was written. You're just to lazy to try to understand it.

                    A Offline
                    A Offline
                    Alexey Serebryakov
                    wrote on last edited by
                    #9

                    @Christian-Ehrlicher Hmm... I'm sorry but I already ask this forum. May be you can explain me.
                    I have already some tree structured data storage something like QMap<QString, QList<QString>> where key of map is parent items and values of map is children. How can I implement my model to view in QTreeView? May be I need to use QAbstractItemModel?

                    That is very simple data storage but I cant find an any good example ot tutorials, in Qt Examples too.

                    Thanks a lot.

                    JonBJ 1 Reply Last reply
                    0
                    • A Alexey Serebryakov

                      @Christian-Ehrlicher Hmm... I'm sorry but I already ask this forum. May be you can explain me.
                      I have already some tree structured data storage something like QMap<QString, QList<QString>> where key of map is parent items and values of map is children. How can I implement my model to view in QTreeView? May be I need to use QAbstractItemModel?

                      That is very simple data storage but I cant find an any good example ot tutorials, in Qt Examples too.

                      Thanks a lot.

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

                      @Alexey-Serebryakov
                      If you use QStandardItemModel/QStandardItems you will be copying your data items into the model. If you already have your own data structures, QAbstractItemModel can be used to supply an interface to your existing data.

                      P 1 Reply Last reply
                      2
                      • JonBJ JonB

                        @Alexey-Serebryakov
                        If you use QStandardItemModel/QStandardItems you will be copying your data items into the model. If you already have your own data structures, QAbstractItemModel can be used to supply an interface to your existing data.

                        P Offline
                        P Offline
                        PaNi
                        wrote on last edited by
                        #11
                        This post is deleted!
                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          Scherer Tech
                          wrote on last edited by Scherer Tech
                          #12

                          I agree with Alexey that the example is incomplete. I am fumbling with setupModelData() and how to connect the model to a QTreeView. The example would be better if code for those two points were included.

                          Christian EhrlicherC 1 Reply Last reply
                          0
                          • S Scherer Tech

                            I agree with Alexey that the example is incomplete. I am fumbling with setupModelData() and how to connect the model to a QTreeView. The example would be better if code for those two points were included.

                            Christian EhrlicherC Offline
                            Christian EhrlicherC Offline
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on last edited by Christian Ehrlicher
                            #13

                            @Scherer-Tech said in Use QStandardItemModel with QTreeView:

                            how to connect the model to a QTreeView

                            See https://doc.qt.io/qt-6/qabstractitemview.html#setModel and https://doc.qt.io/qt-6/model-view-programming.html

                            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                            Visit the Qt Academy at https://academy.qt.io/catalog

                            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