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

André Somers andre at familiesomers.nl
Tue Feb 17 08:02:28 CET 2009


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é
 




More information about the Qt-interest-old mailing list