[Qt-interest] Question on QListView, QAbstractItemModel, and QSortFilterProxyModel

christopherx christopherx at xandros.com
Tue Feb 17 16:46:05 CET 2009


Thanks André :

I tried setRootIndex() in the model, It no seems to work. there is no 
item displayed in the view.  My listview displays blank.  However, from 
the debug messages that I put in model's index(), data() methods, the 
system does found all the A1, A2 ...

Do you know why ?

André Somers wrote:
> Hi Chris,
>
> "christopherx" <christopherx at xandros.com> schreef in bericht 
> news:499A1383.4060001 at xandros.com...
>   
>> Hello there:
>>
>>    I'm a newbee  to Qt,4, and have a question if you can help.
>>    I have a data model built with QAbstractItemModel (subclassed from) in 
>> a tree fashion (ie. RootItem has childrent A, B, and A has children C, C1, 
>> and B has children D, D1 etc..  But I only like to display one level of 
>> nodes at a time, ie (A, B or C, C1) with QListView.   It seems not 
>> possible.
>>    And I tried with QSortFilterProxyModel, but no success;  Any of you had 
>> this issue before ?  How to you handle this  ?
>>     
>
> You can use QListView::setRootIndex to do what you want, I think. Just set 
> it to an invalid index using:
> myListView->setRootIndex(QModelIndex());
> to display the A, B, C nodes. If you want to display A1, A2...An, you set 
> the root node to the index of node A.
>
> André
>  
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>   

-- 

Christopher Xu
Software Developer
*Xandros*
christopherx at xandros.com <mailto:christopherx at xandros.com>
Tel: 1.613.842.3498 x 403 
http://www.xandros.com/




More information about the Qt-interest-old mailing list