要在Qt中添加树节点按钮,可以按照以下步骤进行操作:
QTreeWidget *treeWidget = new QTreeWidget(this);
QTreeWidgetItem *topItem = new QTreeWidgetItem(treeWidget);
topItem->setText(0, "Top Node");
treeWidget->addTopLevelItem(topItem);
QTreeWidgetItem *childItem = new QTreeWidgetItem();
childItem->setText(0, "Child Node");
topItem->addChild(childItem);
QPushButton *addButton = new QPushButton("Add Node", this);
connect(addButton, &QPushButton::clicked, [=]() {
QTreeWidgetItem *newItem = new QTreeWidgetItem();
newItem->setText(0, "New Node");
topItem->addChild(newItem);
});
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(treeWidget);
layout->addWidget(addButton);
这样就可以在Qt中添加树节点按钮了。