PDA

View Full Version : QProxyModel + QQueryModel -> QTreeView



xgoan
1st March 2007, 15:02
Hi.

I want to use the data from a QSqlQueryModel into a QTreeView. But modeling the data into a tree with QProxyModel.

The SQL (create table) code is:

CREATE TABLE categories(
id INTEGER PRIMARY KEY,
parent INTEGER,
image VARCHAR(128),
name VARCHAR(32)
)

parent has the id of the parent :D

Thanks

wysota
1st March 2007, 15:23
Is there a question here somewhere?

xgoan
1st March 2007, 15:41
Is there a question here somewhere?

Mmmm sorry....

How can I implement the QProxyModel inherit class?

wysota
1st March 2007, 20:16
Don't use QProxyModel, but QAbstractProxyModel. Subclass it and reimplement all the pure virtual methods.

Personally I would do it another way. I would implement a subclass of QAbstractItemModel (or QStandardItemModel) and connect appropriate signals to modify the model you want to expose in case the "source" model changes. Of course you can so the same with a proxy model, but then you wouldn't cache all the source items in the exposed model and I believe this is the simplest way to achieve your goal (unless your source model is really big, then it doesn't make much sense to cache items).

xgoan
2nd March 2007, 08:34
For the moment I have done a subclass of QStandardItem that internally execs a query in a update method.

But the idea was have a QSqlQueryModel with a "complex" result and model it in distinct types of ways.

Thanks anyway.