I'm currently looking to a way to get the name of the selected items of a QTreeWidget
.
I have create multiple QTreeWidgetItems
to generate a file browser-like.
I need to know how to get the name of the folder selected.
I have found the
this->MyTree->selectedItems();
to get it but I'm not able to store the feedback which is supposed to be a QList
format.
Any examples on how to store the selectedItems list
?
From the Qt documentation: QTreeWidget Class Reference , QTreeWidgetItem Class Reference
selectedItems()
is a function of QTreeWidget
.
QList QTreeWidget::selectedItems () const
Returns a list of all selected non-hidden items.
text()
is a function of QTreeWidgetItem
QString QTreeWidgetItem::text ( int column ) const
Returns the text in the specified column.
Define a list of QTreeWidgetItem
to store return value of selectedItems()
.
For each item in the list use text()
function to get it's string.
QList<QTreeWidgetItem *> itemList;
itemList = this->MyTree->selectedItems();
foreach(QTreeWidgetItem *item, itemList)
{
QString str = item->text();
//str is what you want
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With