要在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中添加樹節點按鈕了。