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 - show expand indicator/arrow for parents without children (lazy loading)

QTreeView - show expand indicator/arrow for parents without children (lazy loading)

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 796 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.
  • E Offline
    E Offline
    esoteric
    wrote on last edited by
    #1

    I am trying to make a QTreeView use lazy loading. canFetchMore() and fetchMore() are not working as expected.

    Expected: QTreeView items with children that aren't loaded yet but report canFetchMore() -> true should show the expand arrows even when rowCount() -> 0. When the arrow is clicked fetchMore() is called, rowCount() is updated and the items are shown

    Actual: No arrows for items without children, even if they can be lazily loaded.

    What is the best way to do this? I thought about showing them with a QStyledItemDelegate, but I can't find the right function(s) to call.

    JonBJ 1 Reply Last reply
    0
    • E esoteric

      I am trying to make a QTreeView use lazy loading. canFetchMore() and fetchMore() are not working as expected.

      Expected: QTreeView items with children that aren't loaded yet but report canFetchMore() -> true should show the expand arrows even when rowCount() -> 0. When the arrow is clicked fetchMore() is called, rowCount() is updated and the items are shown

      Actual: No arrows for items without children, even if they can be lazily loaded.

      What is the best way to do this? I thought about showing them with a QStyledItemDelegate, but I can't find the right function(s) to call.

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

      @esoteric
      Just one thought: what do you have QAbstractItemModel::hasChildren() return when rowCount() == 0? I think it needs to return true for the expander to be shown?

      1 Reply Last reply
      1
      • E Offline
        E Offline
        esoteric
        wrote on last edited by
        #3

        Hi Jon - I wasn't overriding hasChildren() before, looking at QAbstractItemModel the default implementation is

            return (rowCount(parent) > 0) && (columnCount(parent) > 0);
        

        However I overrode hasChildren() to return true for all folders, but it doesn't make a difference.

        1 Reply Last reply
        0
        • E Offline
          E Offline
          esoteric
          wrote on last edited by
          #4

          I have a QSortFilterProxyModel, and it looks like hasChildren() doesn't work by itself. It also needs canFetchMore().

          JonBJ 1 Reply Last reply
          0
          • E esoteric

            I have a QSortFilterProxyModel, and it looks like hasChildren() doesn't work by itself. It also needs canFetchMore().

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

            @esoteric
            I didn't say hasChildren() works on its own. My reading suggests you need both that and canFetchMore() to return true (when rowCount() == 0) for the QTreeView to show expanders. But are you saying that even with both is still does not work?

            E 1 Reply Last reply
            1
            • JonBJ JonB

              @esoteric
              I didn't say hasChildren() works on its own. My reading suggests you need both that and canFetchMore() to return true (when rowCount() == 0) for the QTreeView to show expanders. But are you saying that even with both is still does not work?

              E Offline
              E Offline
              esoteric
              wrote on last edited by
              #6

              @JonB Sorry, yes, it does work with both. Thanks for your help.

              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