[PyQt] treeview model/view or item-based?

Doug Bell dougb at bellz.org
Mon May 5 21:27:54 BST 2008


Ulrich wrote:
> The tree has 3 to 4 levels. Let's say the first level contains 30 items,  
> the second level 2000 and the third contains 7000 "folders". The last  
> level contains 50,000 items.
>
> I thought it would be a good idea (?) to store the data in a database  
> like SQLite, because this is provided by PyQt and it is searchable. I  
> would store the 50,000 items in one table like this:
> FOLDER_NAME_LVL1,   FOLDER_NAME_LVL2,   .., ITEM_NAME other data
> ...
> with such a table it would be possible to build the tree:
> FOLDER_NAME_LVL1
> +-----FOLDER_NAME_LVL2
> --------+------ITEM_NAME
> etc. etc.
>
> So where is my Problem? Such a tree should be displayed with a  
> QT-Treeview. There are two different ways: Item-based or model-view  
> based. A model-view based approach could become difficult, because the  
> model has to build tree-nodes from a 2-Dimensional Table. Does something  
> like this already exist in PyQt? On the other hand, I have to create all  
> the 50,000 nodes at once if I use the Item-based approach.

You don't actually have to create all items at once with the tree-widget
item-based approach.  You can just create the visible items (that have
open parents).  Then create a method that loads children on demand and
connect it to the itemExpanded(QTreeWidgetItem*) signal.

To get the "+" button to display properly, you can add a single dummy
child item to each closed parent item, then delete it when actually
loading the real children.

Doug.


More information about the PyQt mailing list