在MatchFlags 中有MatchRecursive, 可以查找整个节点树。
仅需或一下MatchRecursive这个flag即可。
有问题HI~
增与删下面是添加的功能:
//这是添加根节点的功能实现this->connect(ui->Root_btn, SIGNAL(clicked(bool)), this, SLOT(addRoot()))void Widget::addRoot()
{
QString one = ui->first->text()
QString two = ui->second->text()
QString three = ui->third->text()
QTreeWidgetItem* item = new QTreeWidgetItem()
item->setText(0, one)
item->setText(1, two)
item->setText(2, three)
ui->Tree->addTopLevelItem(item)
}//这是添加叶子节点的实现this->connect(ui->Child_btn, SIGNAL(clicked(bool)), this, SLOT(addChild()))void Widget::addChild()
{
QString one = ui->first->text()
QString two = ui->second->text()
QString three = ui->third->text()
QTreeWidgetItem* parent = ui->Tree->currentItem()
QTreeWidgetItem* item = new QTreeWidgetItem()
item->setText(0, one)
item->setText(1, two)
item->setText(2, three) parent->addChild(item)
}
添加叶子节点字需要注意父节点的获取就可以了。
下面是删除节点的功能:
this->connect(ui->DEL_btn, SIGNAL(clicked(bool)), this, SLOT(deleteNode()))
void del(QTreeWidgetItem* node){if(node->childCount() >0)
{for(int i = 0i <node->childCount()i ++)
{del(node->child(i))
}
}
else
{
delete node
}
}
void Widget::deleteNode()
{
QTreeWidgetItem* item = ui->Tree->currentItem()
if(item->childCount() >0)
{for(int i = 0i <item->childCount()i ++)
{del(item->child(i))
}
}
delete item
}
删除节点时记得循环删除这个节点下面的所有的子节点。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)