PDA

View Full Version : tree view!!



Seema Rao
9th May 2006, 11:22
375

hi all,
Can some body explain how to implement this tree view.

Thanks in advance,
Seema Rao

Kapil
9th May 2006, 11:26
Hi..

Use the QTreeWidget and then QTreeWidgetItem to create it..
With this you can set the image with every tree item and can subclass it in any hierarchy u need..

Kapil

wysota
9th May 2006, 11:49
Or QTreeView and a model of your choice.

Seema Rao
9th May 2006, 14:01
I tried to create a simple tree view, but no tree appears, Am I doing any thing wrong here??
#include <QApplication>
#include <QtGui>
int main(int argc, char *argv[])

{
QApplication app(argc, argv);

QWidget *widget = new QWidget;
QTreeWidget *treeWidget= new QTreeWidget;

QTreeWidgetItem *cities = new QTreeWidgetItem(treeWidget);
cities->setText(0, "Cities");
QTreeWidgetItem *osloItem = new QTreeWidgetItem(cities);
osloItem->setText(0, "Oslo");
osloItem->setText(1, "Yes");

treeWidget->addTopLevelItem(cities);

QVBoxLayout *mylayout= new QVBoxLayout;
mylayout->addWidget(treeWidget);

widget->setLayout(mylayout);
widget->show();

app.exec();
}
Thanks in advance,
Seema

wysota
9th May 2006, 14:09
Add:

treeWidget->setColumnCount(2);
after you create the tree widget.