PDA

View Full Version : QTreeView items in line



migel
3rd June 2011, 12:50
Is it possible to display children of the top root in line (horizontally instead of line by line)

If that is possible using any of delegate technics please can some one share any of that option, pointing me to the right direction !?

-root1
- child - child - child

-root2
- child - child - child

Thank you

Santosh Reddy
4th June 2011, 00:39
Parent and Child are the concepts of arranging the data on the screen (view) is a hierarchy, it is not required to store parent and child in a hierarchy data structure, this is a main and powerful feature exploited by Model/View Framework.

It may not be possible using delegate, delegate are use to interchange data, and but not to rearrange data (which you want to do in your case)

Not sure what your trying to display, but whatever it be, it up to you to store the data in what every way you want it be, (any data structure / database / file). Now the your question is to how to display them then given formation.

The answer would be implement a custom QAbstractItemModel for the QTreeView, and when the view asks to give children and there columns items, then you need to collect all the children and supply to view as if they were a part of one virtual child, and each actual child as a column of the virtual child.

It is as good as saying (only in your case) that the parent and child terms have different interpretation for a view, and diferent interpretation for you model, that is a child for view is a collection of children for the model.

This is all about how you design your model, and exploit Model/View Framework, to answer in one line, all you need to do is handle things in model which you implement.

migel
5th June 2011, 21:58
Right now I have this working by implementing QListView into child and have all my items in QListView. But this wont work for me in the feature because I am getting lots of QListView's not interacting to each other. It must be one view when I can select individual or all together childs/items.

I think I need look into QAbstractItemModel to see how I can supply a view for a child.

Thanks for explanation.