PDA

View Full Version : about model/view programming



Pang
13th December 2006, 03:17
hi,I want to subclass QAbstractItemModel class for handling the tree-like structure data . But i don't know how to inerst a new item into the "tree" at the given position.Is anyone give me some example? Thanks

jpn
13th December 2006, 06:12
Check $QTDIR/examples/itemviews/simpletreemodel (http://doc.trolltech.com/4.2/itemviews-simpletreemodel.html).

Pang
13th December 2006, 08:29
thanks,But the simpletreemodel just a read only model,it can not resize the model.

wysota
13th December 2006, 08:42
insertRow(rowCount(parentIndex), parentIndex);
QModelIndex ind = index(rowCount(parentIndex), column, parentIndex);
setData(ind, "value");
where parentIndex is the model index of the parent you wish to add a child for. "Under the hood" you have to implement it as a simple modification to your internal data structures and you can see in the simpletreemodel example how to do it (just look at its code, not the app itself - the model is initialised on startup).