QTreeView - show expand indicator/arrow for parents without children (lazy loading)
-
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.
-
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.
-
@esoteric
I didn't sayhasChildren()
works on its own. My reading suggests you need both that andcanFetchMore()
to return true (whenrowCount() == 0
) for theQTreeView
to show expanders. But are you saying that even with both is still does not work?