Qt - QTreeWidgetItem未被编辑

时间:2012-09-22 17:30:38

标签: c++ qt

为什么我的QTreeWidgetItem无法编辑?我用这段代码来实现一个:

ui->treeWidget->expandAll();
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(0, "Add details about your Bug");
bug->addChild(item);
ui->treeWidget->editItem(item, 0);

1 个答案:

答案 0 :(得分:1)

您忘记在QTreeWidgetItem中将editable设置为true(默认为false):

ui->treeWidget->expandAll();
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(0, "Add details about your Bug");
item->setFlags(item->flags() | Qt::ItemIsEditable);
bug->addChild(item);
ui->treeWidget->editItem(item, 0);