How to get rid of expande/collapse +/- QTreeWidgetItem indicator?
I read in the documentation that I can get rid of the +/- indicator with the setChildIndicatorPolicy method of hte QTreeWidgetItem class. And I did it with the following code. But i can still see the indicator when I run the code.
Does anyone know what could possibly be wrong? Am I using the right method?
QTreeWidgetItem *item2 = new QTreeWidgetItem();
Just tested locally, this works:
TreeViewTestForm::TreeViewTestForm(QWidget *parent) :
QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeWidget); item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator); item->setText(0, "abc"); QTreeWidgetItem *item2 = new QTreeWidgetItem(item); //item2->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator); item2->setText(0, "xxxx");
I see no significant difference to your code (despite the missing parents to the item constructors).
Thank you Volker. I will copy your code to a new project and test it on my end. See if that may help me debug the problem.
Volker, your code still shows root decorations on my end. I figured a method that worked for me. The following line got rid of the expansion indicators and root decoration:
there is a difference in showing a root item and showing the expand / collapse items.
Removing the rpoot is possible by setRootIsDecorated(false);, the other one by the solution given by Volker. But rootDecoration != expand/collaps indicator
yeah, I know the difference after reading about the root decorator and the expandable symbols (+/-) . As I mentioned in my first post I had already tried using the setChildIndicatorPolicy() method of the QTreeWidgetItem, as Volker also did.
I tried Volker code and his code works in the sense that it does not show the expandable icons. (at first I thought the root decorator his code showed was part of the expandable icons, but i realized that it was a root decorator later).
In any case, setChildeIndicatorPolicy() works in his example but when I applied it in my code it doesn't.
So I read more and the documentation and found that the QTreeWidget->setRootIsDecorated() is another way to control the appearance of the expandable icons.
Below is the definition straight from the Qt 4.7 documentation, and it works in my code. But I am still not satisfied that the setChildIndicatorPolicy() of the QTreeWidgetItem class is not working.
rootIsDecorated : boolThis property holds whether to show controls for expanding and collapsing top-level items.
Items with children are typically shown with controls to expand and collapse them, allowing their children to be shown or hidden. If this property is false, these controls are not shown for top-level items. This can be used to make a single level tree structure appear like a simple list of items.
By default, this property is true.
bool rootIsDecorated () const
void setRootIsDecorated ( bool show )