Reputation: 6074
In my project I'm using a QTreeView
in order to display a plot configuration. On top I have a root node called PlotConfig
containing several plot windows. Each plot window contains several simple xy plots.
So basically, I have something like this:
I'm using my own QAbstractItemModel
in order to display this plot configuration. It all works fine, but the root node PlotConfig
is really distracting the user.
So I want something like this:
Is there a way to disable the showing of the root node? Either directly in QTreeView
or in the QAbstractItemModel
. What I basically want is a QList
but with each entry behaving like a tree.
Upvotes: 5
Views: 4398
Reputation: 319
I needed the same appearance, eventually realized the tree can have multiple 'root' nodes (beneath the implicit invisible root node) i.e. can call addTopLevelItem for Window1, Window2, Window3 etc.
QTreeWidgetItem* rootItem;
rootItem = new QTreeWidgetItem (ui->tree->invisibleRootItem());
rootItem->setText(0, "Window1");
ui->tree->addTopLevelItem(rootItem);
rootItem = new QTreeWidgetItem (ui->tree->invisibleRootItem());
rootItem->setText(0, "Window2");
ui->tree->addTopLevelItem(rootItem);
Upvotes: 1
Reputation: 301
setRowHidden also hides the child nodes which (I guess) is not intended. In your example you have got a root node called PlotConfig. I assume it is a child node of the invisibleRootItem. In such a case you need to use setRootIndex:
setRootIndex(model.invisibleRootItem()->child(0, 0)->index());
This should give you the desired result.
Upvotes: 4