Is there an error in my code to populate QTreeView?

I am using PyQt 4.4.

Best shown using some shots. All nodes must have leaves from 0 to 99. They are incrementally loaded using canFetchMore()and fetchMore(). But for some reason I don’t know that this only works for the root of the node. (Picture 1)

If I destroy and expand node, it loads an additional 10 values. (Figure 2 and 3)

It is also strange that it loads 10 values, since the code only loads 5 per call fetchMore(), which means it is called 2 times before the code stops loading more data.

Screenshot 1 http://i27.tinypic.com/ezyic.png Screenshot 2 http://i32.tinypic.com/2ymunpx.png Screenshot 3 http://i27.tinypic.com/283zfr.png

I wrote a small example to demonstrate the problem, just run it with python test.py. http://snipt.org/lLh

Does anyone know what causes this error?

+3
source share
1 answer

I took a look at the source of Qt (v4.5, although I do not expect much difference between v4.4 and v4.5) for QAbstractItemView and QTreeView, and I do not think that they support gradual lazy loading of child nodes.

QAbstractItemView has no concept of trees, so it only calls fetchMore()at the very top index. It causes fetchMore()when:

  • Geometry Updated
  • Scroll bars move
  • Rows are inserted
  • Current item changed as a result of autoscroll drag and drop operation

QTreeView fetchMore(), :

  • (, , , fetchMore() )
  • , , expandAll() collapseAll()

, QTreeView, fetchMore() ​​ .

+6

Source: https://habr.com/ru/post/1713583/


All Articles