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 does a QTreeview get populated

How does a QTreeview get populated

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 701 Views 1 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I am trying to create a QAbstractProxyModel between an SQL table model and a QTreeview. The problem I'm having is that the base level items don't have the branch indicators to show it's children. All the data of the shown items looks fine.

    I was expecting the 'index' or 'hasChildren' to be from one of the base level items during initialisation but it does not seem to be the case.

    The way I'm determining which level an item lives is by from the first column of the table which has a stirng like "0.0.1" for the first base item's first item's second item.

    sierdzioS 1 Reply Last reply
    0
    • ? A Former User

      I am trying to create a QAbstractProxyModel between an SQL table model and a QTreeview. The problem I'm having is that the base level items don't have the branch indicators to show it's children. All the data of the shown items looks fine.

      I was expecting the 'index' or 'hasChildren' to be from one of the base level items during initialisation but it does not seem to be the case.

      The way I'm determining which level an item lives is by from the first column of the table which has a stirng like "0.0.1" for the first base item's first item's second item.

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @Sillie_wous said in How does a QTreeview get populated:

      I was expecting the 'index' or 'hasChildren' to be from one of the base level items during initialisation but it does not seem to be the case.

      In your model, both hasChildren() and rowCount() need to return correct data for the hierarchy to be shown correctly in QTreeView. And yes, code in index() needs to be correct as well.

      (Z(:^

      ? 1 Reply Last reply
      3
      • sierdzioS sierdzio

        @Sillie_wous said in How does a QTreeview get populated:

        I was expecting the 'index' or 'hasChildren' to be from one of the base level items during initialisation but it does not seem to be the case.

        In your model, both hasChildren() and rowCount() need to return correct data for the hierarchy to be shown correctly in QTreeView. And yes, code in index() needs to be correct as well.

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        @sierdzio At which point do these functions get called so I can debug the issue? I've treid looking trough the source of QTreeView but don't see it anywhere. Now I just have a break point at those functions but they don't seem to get called from the base level items, only the root item.

        sierdzioS 1 Reply Last reply
        0
        • ? A Former User

          @sierdzio At which point do these functions get called so I can debug the issue? I've treid looking trough the source of QTreeView but don't see it anywhere. Now I just have a break point at those functions but they don't seem to get called from the base level items, only the root item.

          sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          @Sillie_wous said in How does a QTreeview get populated:

          @sierdzio At which point do these functions get called so I can debug the issue?

          They're called all the time. When view is initialised, when mouse hovers over the view, when focus changes - really they are typically called hundreds of times whenever you do anything in the app.

          I've treid looking trough the source of QTreeView but don't see it anywhere. Now I just have a break point at those functions but they don't seem to get called from the base level items, only the root item.

          The view starts at root item because initially it does not know anything more. So first, it will check index(QModelIndex()) to get the root item (in QTreeView, the root is invisible!), then it will check if root has children, then it will call index() for all items, and it will call data() for all roles to get all data that needs to be displayed. Then rinse and repeat for all children, their children etc.

          (Z(:^

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

            As a side note, the model test is a great tool to debug custom models

            "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
            1
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by A Former User
              #6

              So after some more digging I think I have found the problem, QTreeViewPrivate::hasVisibleChildren returns false for all base level items. Apparently 'ItemNeverHasChildren' is true. Which makes sense since the source model is a table.

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

                So you have to override the flag() method to fix that

                "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
                0

                • Login

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