PDA

View Full Version : Categorizing data.



kaushal_gaurav
18th August 2008, 07:50
Hi,

I want to categorize data in a QTableView means... I have sorted a coluumn of a QtableView
and i want to give sub headings to the data in the table.

Like i have sorted on device type column and i need to paint sub headings on all devices according to device type group.

see attachment.

Please help..!!!!!!!

Regards,
Gk

kaushal_gaurav
18th August 2008, 08:57
Hi,

Is there a solution to this?

GK

wysota
18th August 2008, 11:36
I think what you really want is QTreeView.

kaushal_gaurav
18th August 2008, 12:02
No i need to disply the data in tabular form. there are more columns apart from one shown in attachment. but the categorization is based on one column.

wysota
18th August 2008, 12:09
Still you want a tree view because you want two levels of data - headers and body (similar to how Qt Designer displays widget properties).

kaushal_gaurav
18th August 2008, 12:28
ok... but how can i proceed ...
some example code....

wysota
18th August 2008, 12:40
Have a two level model - upper level for headers, lower level for items. Then apply the model to the tree view. Next you'll have to provide a custom delegate for your view to display the headers properly. Finally adjusting some properties of the view and expanding all the items will probably be needed

kaushal_gaurav
18th August 2008, 15:12
But the data that i have to display is already in a model which is derived from QAbstract ProxyModel.

Do i have to replicate the data..but that would be bad..

Is there some reference material..?

wysota
18th August 2008, 16:17
You don't have to replicate data. Just make your proxy restructurize it into two level hierarchy.

kaushal_gaurav
18th August 2008, 17:25
Thanks...
Theoretically it is ok ..but how do i put it in code..?

wysota
18th August 2008, 19:21
You'll have to change your parent(), index(), rowCount() and data() methods. The top level items are artificial so you can't map them to source indexes, thus you have to provide implementations for above mentioned methods for them. rowCount() for the top level (invalid parent) will return the number of groups (headers) and for the lower levels (parent points to group item) the number of items in a particular group. Same goes for the remaining methods.