PDA

View Full Version : How to merge QTableView and QTreeView ???



Xaleandr
28th December 2007, 19:16
Hello everybody,

I have a problem how to merge a QTableView and QTreeView.

Originally, I have an SQL table of type:


-------------------------------------------------
| Name | Surname | Profession | Age
-------------------------------------------------
| John | Smith | Engineer | 25
| Mike | Parrot | Designer | 35
| Alex | Funny | Engineer | 45
| Alex | Fellow | Designer | 29
| Alice | Young | Secretary | 20
--------------------------------------------------

The simplest way to represent data is to use QSqlTableModel and get a single table.

My question is, if it is possible to merge QTableView and QTreeView and represent result as a tree of tables, based by one of the fields, e.g. by "Profession":


+---Engineer:
| -------------------------------------------------
| | John | Smith | engineer | 25
| | Alex | Funny | engineer | 45
| -------------------------------------------------
|
+---Designer:
| -------------------------------------------------
| | Mike | Parrot | designer | 35
| | Alex | Fellow | designer | 29
| -------------------------------------------------
|
+---Secretary:
-------------------------------------------------
| Alice | Young | Secretary | 20
-------------------------------------------------



Thanks in advance for possible hints,
Xaleandr

marcel
28th December 2007, 19:47
Yes, with a multicolumn model for the QTreeView.
For an example take a look at the sources of QDirModel and the example Directory View, from the Item Views section. Another example is Interview from Qt Demos.

Xaleandr
29th December 2007, 18:58
Thanks a lot, I'll have a look.