[Qt-interest] QTreeView::expandAll() bug ?

Benjamin Meyer ben at meyerhome.net
Fri Jun 19 20:18:55 CEST 2009


On Jun 19, 2009, at 1:54 PM, Stephen Collyer wrote:

> 2009/6/19 Benjamin Meyer <ben at meyerhome.net>
>
>>
>> On Jun 19, 2009, at 5:53 AM, Stephen Collyer wrote:
>>
>> I have a QTreeView displaying a subset of a QFileSystemModel
>>> which looks like, say:
>>>
>>> level_1/a_file
>>> level_1/b_file
>>> level_1/level_2
>>> level_1/level_2/c_file
>>> level_1/level_2/level_3
>>> level_1/level_2/level_3/d_file
>>>
>>> When I call QTreeView::expandAll(), the level_3 directory is not  
>>> displayed
>>> as expanded in the view, though level_2 is displayed as expanded.
>>>
>>> Is this a bug ?
>>>
>>> --
>>> Stephen Collyer
>>>
>>
>> Maybe not the best api, but it is behaving correct.  expandAll is a  
>> one
>> time operation to expand everything it currently has.   
>> QFileSytemModel
>> doesn't know about level_3 until some time after level_2 is opened  
>> (being
>> lazily populated).  You probably want a keepAllExpanded()  
>> function.  An
>> alternative is to use QDirModel which will load level_3 as soon as  
>> level_2
>> is opened (if level_3 is big this can stale the ui of course).
>>
>
> [please reply to the list, not to me]
>
> Yes, I think that you're right. The problem is probably with the
> lazy-fetching
> model. I'm trying to implement a "select all items" method, too, and I
> suspect
> that this is causing problems there as well. I'm trying to use  
> fetchMore()
> to
> populate the model as I walk the dir tree, but it doesn't seem to be  
> doing
> so,
> for some reason.
>
> I'm not finding the model/view classes nearly as easy to use as I'd
> expected.

When you call fetchMore on QDirModel it will immediately fetch, while  
in QFileSystemModel it will ask its private thread to do it.  As some  
point in the near future the thread will return the results to the  
model and it will add new rows.  It really sounds like you want to use  
QDirModel rather then QFileSystemModel.  This behavior difference is  
the primary reason why QDirModel is not depreciated as some  
applications want to have that information immediately rather then  
lazily.

-Benjamin Meyer



More information about the Qt-interest-old mailing list