PDA

View Full Version : Making a tree proxy model with multiple sources



Mookie
2nd February 2010, 14:29
I have several SQL table models. Each has column representing a primary key, foreign key pointing to parent's primary key (optional for 1st level table), and some text data. I want to display these in a QTreeView. I must admit that rolling my own from QAbstractItemModel has me stumped.

I have looked at the TransposeProxyModel example, but it assumes one if going from table to table. No tree representation.

My best try, so far, has been starting with Editable Tree Model, and changing the stored data in each TreeItem to be a sourceIndex instead of a stored value. I break down when trying to connect my source rowsInserted signal and have it call my insertRows in a private slot.

Does anyone know of a good example of taking SQL data and displaying it in a QTreeView?
Something that would update robustly if the source models changed.
I would accept read-only (no editing).
I am not against moving down to QSqlQueryModel for the underlying models, but would like to stick with QSqlTableModel, if possible.
I would even accept a flat LEFT JOIN representation underneath, if need be.

cia.michele
17th August 2010, 13:37
I need the same too but I don't know how can obtain it, I'm a newbie of qt.
Try to see the answer to my post of 26th December 2009 called "Master/detail presentation", there is an example to how to use a two-level grid populate by an only one StringList model. How can we create a model for this view, a gerarchical SQL Model? Have you got any ideas?

Thanks for your time!

Michele

peterius
18th August 2010, 04:28
If you follow the documentation at http://doc.trolltech.com/4.6/model-view-programming.html exactly with the SQL as your model, then that might be what you're looking for.

But if you want it to be robust, don't use Qt.