代码:
//treeWidget树控件
//1:设置头部标签 QStringList()匿名对象创建
ui->treeWidget->setHeaderLabels(QStringList()<<"英雄"<<"英雄介绍");
//2:设置item
QTreeWidgetItem * liItem = new QTreeWidgetItem(QStringList()<<"力量");
QTreeWidgetItem * minItem = new QTreeWidgetItem(QStringList()<<"敏捷");
QTreeWidgetItem * zhiItem = new QTreeWidgetItem(QStringList()<<"智力");
//添加顶层级别的item
ui->treeWidget->addTopLevelItem(liItem);
ui->treeWidget->addTopLevelItem(minItem);
ui->treeWidget->addTopLevelItem(zhiItem);
//3:创建子item并挂在到顶层item上
QStringList heroL1;
heroL1<<"英雄1"<<"技能描述技能描述技能描述技能描述";
QStringList heroL2;
heroL2<<"英雄2"<<"技能描述技能描述技能描述技能描述";
QTreeWidgetItem * l1 = new QTreeWidgetItem(heroL1);
liItem->addChild(l1);
QTreeWidgetItem * l2 = new QTreeWidgetItem(heroL2);
liItem->addChild(l2);
展示: