1
votes

Im working with a Qt GUI application, and i have a QTreeWidget with values. I have added each value to the tree like so:

QTreeWidgetItem *node = new QTreeWidgetItem();
node->setText(0, m_stringList[i];
node->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemisDragEnabled);
ui->sourceTreeWidget->addTopLevelItem(node);

What i am trying to implement now, is a delete button to allow the user to select one or multiple tree items by clicking them, and then pressing the delete button.

The button part is easy.

The part i need some help with, is finding out how to retrieve the string/text value of the currently selected tree item(s).

Anyone have some tips or hints?

1

1 Answers

2
votes

What exactly is your problem with that? You create a SLOT for the button and retrieve a list of the selected items with

QList<QTreeWidgetItem*> sel_items = ui->sourceTreeWidget->selectedItems();
for(int i=0; i<sel_items.size(); i++){
    ...
}

as stated in the documentation for QTreeWidget. You may then iterate through the list and delete them directly or simply retrieve the string/text value as you asked.