Qt 树形结构
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
QTreeWidget* tree = new QTreeWidget(this);
tree->setColumnCount(1); //set the number of the colume
tree->setHeaderLabel(tr("relation net"));
tree->show();
//set the widgetitem
QTreeWidgetItem *item1 = new QTreeWidgetItem(tree,QStringList(QString("friend")));
QTreeWidgetItem* item1_1 = new QTreeWidgetItem(item1);
item1_1->setText(0,"jim");
QTreeWidgetItem *item2 = new QTreeWidgetItem(tree,QStringList(QString("parents")));
// item2->setText(1,"parents");
QTreeWidgetItem* item2_2 = new QTreeWidgetItem(item2);
item2_2->setText(0,"mom");
tree->expandAll();
// QTreeWidgetItem *imageItem1_1 = new QTreeWidgetItem(imageItem1,QStringList(QString("Band1"))); //子节点1
// imageItem1->addChild(imageItem1_1); //添加子节点
// QTreeWidgetItem *imageItem2 = new QTreeWidgetItem(ui->treeWidget,QStringList(QString("图像2")));
// QTreeWidgetItem *imageItem2_1 = new QTreeWidgetItem(imageItem2,QStringList(QString("Band1"))); //子节点1
// QTreeWidgetItem *imageItem2_2 = new QTreeWidgetItem(imageItem2,QStringList(QString("Band2"))); //子节点2
// imageItem2->addChild(imageItem2_1); //添加子节点
// imageItem2->addChild(imageItem2_2);
// ui->treeWidget->expandAll();
}
Widget::~Widget()
{
delete ui;
}