[Qt-interest] QTree

Konrad Rosenbaum konrad at silmor.de
Thu Jan 20 22:03:47 CET 2011


On Thursday 20 January 2011, Alex Strickland wrote:
> I am just starting out to learn about Model/View via the Simple Tree
> Model example. The tree used in the example looks functional, but it
> lead me to look for a QTree (or similar) class but I couldn't find
> anything. Is there such a thing?

It depends on whether your data is (half-)static or dynamic.

If you can determine all elements of the tree before you display them and 
they aren't too many to fit into memory, then you can just use 
QStandardItemModel, which is a pretty good abstraction of all the trees and 
tables you can display with Qt. This also works most of the time if the tree 
changes only slightly and with a low update rate.

If you query child elements when you click the parent or they change 
dynamically and often upon user action, you would have to write your own 
sub-class of QAbstractItemModel to interface with the real dynamic data 
source.

QStandardItemModel has the upside of being very easy to use and saving you a 
lot of headaches, it has the downside of  duplicating your data. So you use 
it if the duplication and synchronization is less effort than adapting 
QAbstractItemModel to fit your data source or if your data source is too 
slow to work well with a GUI.


	Konrad
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110120/98b9bbfb/attachment.bin 


More information about the Qt-interest-old mailing list