Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the indices of QListWidget::selectedItems()?

I have QListWidget and I need to get the indices of selected items. (I could work with items in the list by values, but I have std::vector that contains some objects for each item in the list and I also need to delete them from it.) There is a fucntion indexFromItem but it's protected(?) so I can't use it.

Any ideas?

QList<QListWidgetItem *> itemList = lw1->selectedItems();
like image 652
Denis Avatar asked Sep 21 '25 05:09

Denis


1 Answers

You can use maybe:

list->selectionModel()->selectedIndexes()

Where list is an instance of QListWidget.
Not sure if it returns exactly what you are looking for.

From the documentation:

Returns a list of all selected model item indexes. The list contains no duplicates, and is not sorted.

QListWidget has a method named selectedIndexes as well, but it is a protected one, so you have to use such a tricky way to get them.

like image 146
skypjack Avatar answered Sep 22 '25 19:09

skypjack