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. [Solved] QAbstractItemModel::data() is not called for all tree subitems

[Solved] QAbstractItemModel::data() is not called for all tree subitems

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 3.6k 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.
  • M Offline
    M Offline
    mvidelgauz
    wrote on last edited by
    #1

    Hello, I have I QAbstractItemModel-derived class attached to QTreeView
    Model implements 2 top-level rows and one of them has 3 sub-rows. Only first 2 sub-rows are displayed. If add one "dummy" top-level row then everything is displayed.

    I used qDebug() to print how many times QTreeView calls my model::data() and with what indexes (only Qt::DisplayRole cases are printed) and see that it is actually called 2 times for sub-rows instead of 3.

    Of course, first suspicion is that my model::rowCount() is incorrect and makes QTreeView "think" that there are only 2 sub-rows. So here are qDebug() prints:

    rowCount returning 3 for parent 0xbc6f70
    .......
    Qt::DisplayRole for row 0 ,column 0 pointer 0xbc6fc0 parent= 0xbc6f70
    Qt::DisplayRole for row 1 ,column 0 pointer 0xbc7068 parent= 0xbc6f70

    0xbc6f70 is:
    parent.internalPointer() in model::rowCount(const QModelIndex &parent)
    index.parent().internalPointer() in model::data(const QModelIndex &index, int role)

    So why is model::data() being called for row 0 and row 1 but not for row 2 if model::rowCount() returned 3 for index with internalPointer() 0xbc6f70 ?

    Thank you!

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      Perhaps the third row would not be visible in the view and therefore does not need to be queried?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mvidelgauz
        wrote on last edited by
        #3

        Hello ChrisW67,
        thank you for your reply.

        Why shouldn't 3rd row be visible?
        Why is it queried and shown when I am increasing number of main rows till 3?

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          bq. Why shouldn’t 3rd row be visible?

          If the view determines that the third row would not be visible on the screen then there is no reason to query the data in that row.

          bq. Why is it queried and shown when I am increasing number of main rows till 3?

          If you mean that changing the number of rows at the top level changes the number of visible rows lower down the the tree then your model must be incorrectly implemented.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mvidelgauz
            wrote on last edited by
            #5

            [quote author="ChrisW67" date="1374792147"]

            If you mean that changing the number of rows at the top level changes the number of visible rows lower down the the tree then your model must be incorrectly implemented.[/quote]

            Yes! And this is exactly what my question is about! What could be wrong in my implementation? I printed result of my rowCount() (see my first post) and it returns 3:
            rowCount returning 3 for parent 0xbc6f70

            where 0xbc6f70 is parent of those 3 lower level rows. This is what is happening:

            1.rowCount() for parent return3
            2. data() is called only 2 times - for rows 0 and 1

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mvidelgauz
              wrote on last edited by
              #6

              The problem was in my QSortFilterProxyModel-derived class that didn't take into account sub-items )))

              Thank you ChrisW67 for trying to help me!
              Actually, your first reply could already lead me to this answer - some of my (sub)items would not be visible in the view and therefore does not need to be queried - because they were filtered out by filter model!

              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