PDA

View Full Version : How to set visible the QTreeWidgetItem expand '+' mark



mcostalba
13th January 2007, 13:49
Hi,

I use a QTreeWidget to show 'virtual' files and directories. It means not real files and directories on the file system, but a list of directories/files retrieved from an archive.

Because retrieving the list of files under a given directory it's a slow operation this is done only on request, i.e. when user clicks and expand on a given directory name.

Problem is that QTreeWidget shows as 'expandable' with the '+' sign only items that have already children. But directories are populated 'only' when expanded so I would like to set the expand '+' mark also on items without children.

This example to better clarify:

On startup QTreeWidget is populated with

-firstFile
-secondFile
-firstDirectory

firstDirectory has no childern at the moment. Only when user expands the directory then firstDirectory is populated. The problem is that firstDirectory is shown without the '+' mark so user cannot expand it, and directory will never be populated.

e8johan
13th January 2007, 14:48
In Qt 4 you can create a lazy model... but for Qt 3 I guess that you could add a child to all non-searched nodes called "Searching..." or "Updating..." or something. When you have searched it you remove that item and place any actual children there.

mcostalba
13th January 2007, 15:30
Actually I'm working on Qt4.

What is a lazy model? is it settable on a QTreeWidget?

varcon
14th January 2007, 04:21
What about adding a single child item named "Progressing..." (or s.th. similar)? The user will be able to expand it and will be notified that it will take some time to display the contents.

Another way is to create a custom item delegate (they are responsible for painting the items) and react on itemActivated. This will you give you some more possibilities, such as showing the user that s.th. is progressing (e.g. a small progressing bar inside the item).