PDA

View Full Version : QTreeWidget: How to display the root item?



Johannes
25th January 2011, 11:04
Hello.
I'm building a Qt application with a QTreeWidget. I've got several TopLevelItems each with some childs. But all the Items are "hanging" on the top end of the QTreeWidget like this:

|
[-]TopLevelItem1
| |
| -Child1
| |
| -Child2
|
[-]TopLevelItem2
|
-Child3
I read in the documentation that there is a "invisibleRootItem", but I got no success to make it visible.
How can I display the root item?
I wanted to have a tree like this:

RootItem
|
[-]TopLevelItem1
| |
| -Child1
| |
| -Child2
|
[-]TopLevelItem2
|
-Child3

wysota
25th January 2011, 11:06
You don't want to make it visible. You want to set rootIsDecorated property to false.

Johannes
25th January 2011, 11:28
My primary intention was to display the root item, but your suggestion to try the property rootIsDecorated lead also to a good looking result.
I tried it and now my topLevelItems are childs and my new topLevelItem looks like a root item. Thanks! :)

wysota
25th January 2011, 11:35
You can't display the invisibleRootItem because it is a fake item used only to have an equivalent of empty QModelIndex.

Johannes
25th January 2011, 11:39
That's a good reason. Thanks for the explanation.