[Interest] Tree Model and QListView

Tony Rietwyk tony at rightsoft.com.au
Thu Sep 27 17:12:44 CEST 2012

Hi Pierre, 


Have a look at setRootIndex.  Both QListView and QTableView can point
anywhere within a tree model.  


Hint:  When you can't find a function in a Qt class - make sure to click on
the 'List of all members' link in the Assistant.  Especially the more high
level classes!   Despite the name, the abstract base classes often have
loads of in-built functionality.  


Hope that helps, 






From: interest-bounces+tony=rightsoft.com.au at qt-project.org
[mailto:interest-bounces+tony=rightsoft.com.au at qt-project.org] On Behalf Of
Pierre-√Čtienne Messier
Sent: Thursday, 27 September 2012 11:41 PM
To: interest at qt-project.org
Subject: [Interest] Tree Model and QListView




Let's take the Simple Tree Model example (
http://qt-project.org/doc/qt-4.8/itemviews-simpletreemodel.html ) with the
TreeModel and TreeItem classes. Let's say the internal data structure looks
like this:




+ Category1

|------ Item

|------ Item 

|------ Item 


+ Category2

|------ Item

|------ Item 

|------ Item 





I want to display that model inside a custom QListView to only show one
Category at a time. So far, I ran a few tests and for example, setting the
root element (in the model) as Category2 will indeed show only Category2 in
the QListView (desired behavior).


I want that when navigating with the keyboard arrows left-right keys would
"reset" the model root node inside the QListView (Category1, then Category2
and so on). Would it be a good idea to:

1.	Subclass QListView to catch the Left/Right arrow keypress
2.	Destroy the current model in the view, creating a new model with the
new desired root element
3.	Replace the model in the view by the new one

On paper, it seems quite inefficient to me. Any experience with that kind of
operation? Could I just do this all inside one model instead?




Pierre-√Čtienne Messier

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120928/f9ef0ca8/attachment.html>

More information about the Interest mailing list