[Qt-interest] QSqlQueryModel to QTableView problem
Stephen Kelly
steveire at gmail.com
Tue Feb 2 19:27:57 CET 2010
Gillen Daniel wrote:
> Hi @all
>
> I am facing some sort of problem here and don't seem to find a solution
> anywhere :(
>
> I have an SQL table containig objects with some sort of path-like id's.
> As an example:
>
> '/0', other fields....
> '/0/1', ......
> '/0/1/test.txt', .......
> '/0/2', ....
>
> I want to display these rows in a QTreeView in the following manner:
>
> /
> |-- /0
> | |-- /0/1
> | |-- /0/1/test.txt
> |-- /0/2
>
> I've set up a QSqlQueryModel that only queries the first column from the
> database and am setting it with setModel() to my QTableView but all
> items are displayed as "root objects" and don't make some sort of tree.
>
> Can anyone give me a hint on how I can manage to get a tree? How does I
> tell QTreeView that there are parents and childrens that are recognized
> by the '/' char in my query results?
You can
a) Implement your own QAbstractItemModel to query the data and put it in
the database.
b) Write a proxy model to turn the list into a tree.
The first option is probably easier. I've been working on a proxy model to
do the transformation, but it's not finished and it's very non-trivial:
http://steveire.wordpress.com/2010/01/06/testing-proxy-models-gets-easier-
again/
I think if you search the archives you'll find others asking the same
question and going the implement own model route.
All the best,
Steve.
>
> Thx in advance.
>
> Dan
More information about the Qt-interest-old
mailing list