PDA

View Full Version : QTreeWidgetItem



Sarma
6th April 2006, 20:43
Hi all
QTreeWidgetItem-i tried to add items to the tree using QTreeWidgetItem
but they dint get added.
here r the steps wat i did.
1-created a QTreeWidget
2-added item using QTreeWidgetItem(QStringList(QString))

is tht correct?
plz do reply
very urgent
thanks iin advance
Sarma

jpn
6th April 2006, 20:52
From QTreeWidget docs:
In its simplest form, a tree widget can be constructed in the following way:

QTreeWidget *treeWidget = new QTreeWidget();
treeWidget->setColumnCount(1);
for (int i = 0; i < 10; ++i)
new QTreeWidgetItem(treeWidget, QStringList(QString("item: %1").arg(i)));
Before items can be added to the tree widget, the number of columns must be set with setColumnCount().

You can create QTreeWidgetItems (take a look at its constructors) with QTreeWidget as parent which leads a top level item to be created, or with another QTreeWidgetItem as parent which leads a child to be created.
You can also add top level items by QTreeWidget::addTopLevelItem().
Childs to a specific item can be added by QTreeWidgetItem::addChild().

These aren't even all, and as you can see, there are several ways to construct a tree.
Just take a look at the docs, there are examples there..