PDA

View Full Version : QAbstractItemModel to different views



ganeshshenoy
19th February 2008, 04:47
Hi,

I need to display the data from QAbstractItemModel to different views say to Treeview and list view. QAbstractItemModel contains a QList of structs. And struct has marks of students for 6 subjects. The Treeview should display sum of all marks, and ListView will have 6 columns and has to display each marks in separate columns. What is the best way i can do this?

Tree view sample
- marks
+-- 80
+-- 90


List view sample
col1 | col2 | col3 | col4 | col5 | col6
--------------------------------------------------
10 | 20 | 10 | 20 | 10 | 10
10 | 20 | 10 | 20 | 10 | 20

jpn
19th February 2008, 12:34
Hi,
Hi


I need to display the data from QAbstractItemModel to different views say to Treeview and list view. QAbstractItemModel contains a QList of structs. And struct has marks of students for 6 subjects. The Treeview should display sum of all marks, and ListView will have 6 columns and has to display each marks in separate columns.
QListView cannot handle multiple columns so in fact both will be tree views. ;)


What is the best way i can do this?

Tree view sample
- marks
+-- 80
+-- 90


List view sample
col1 | col2 | col3 | col4 | col5 | col6
--------------------------------------------------
10 | 20 | 10 | 20 | 10 | 10
10 | 20 | 10 | 20 | 10 | 20
Put a proxy model in between which makes it flat. Something like FlatProxyModel at http://www.thorsen-consulting.dk/freebies.html.

ganeshshenoy
19th February 2008, 14:41
Having tree view in both the case is a good idea. My model returns (thru data function) the sum of the marks. How can send for first view the sum and for the second view the individual marks. Or is there any other way where view can manipulate this?

jpn
19th February 2008, 14:43
A model cannot return different data for different views. Therefore you must put a proxy model of some kind between model and either view.