PDA

View Full Version : How to integrate detailed information (with interaction/buttons) inside a QTreeView?



caduel
4th July 2008, 16:58
I need to display a "list" of entries.
[Something like: a list of persons, and collapseable displayable:
* a HTML rendered business card
* perhaps a collapseable list of hobbies
* to the left: perhaps an image of that person
* etc.
It boils down to: I have a list of stuff and would like to display various "details" usually upon user request. I do not want these to pop up in separate windows but integrated in that list.]


Each entry has some attributes. Obvious choice: a QTreeView.

However, I need to support displaying additional content.
This content should be

calculated on demand
collapseable
large: span all the columns; take the space of several rows
probably HTML (text in different colors at the very least)
contain small buttons (possible hyperlinks are ok), but real buttons might be required
(collapseable) beneath a row.

Spanning column one, collapsing etc is supported by QTreeView.
But... is it also possible to add further widgets inside the (probably delegate rendered HTML?) I also would like to interact with this "details subview" without going into edit mode or so.

Is it possible to do that with a QTreeView (or another existing Qt widget, for that matter)?
Or do I have to create a new widget (rather: put lots of widgets in layouts) to achieve that?
Are there empirical results on how many widgets at the same time are manageable with Qt (4.4)?
(I would need to be able to show at least 100 rows. If all content is done with QLabels, QFrames, and Buttons that would mean several thousand widgets, I guess. Might be a performance issue.)

I hope my problem is somewhat clear.

Looking forward to your suggestions
Christoph

fullmetalcoder
4th July 2008, 17:17
I'd suggest creating a model that holds your data so that is shows the list properly in a tree view.

Each of these item would pretend to have one child but you can return an invalid variant upon any data() call for these.

Then you have to create a custom delegate or to set a custom widget for each of these child items so that it displays your additional data. (the widget is probably the simplest way and the delegate the most performant and lightweight...). Use QAbstractItemView::setItemDelegateForRow() or QAbstractItemView::setIndexWidget() to achieve this