PDA

View Full Version : QListWidget multiselection indexes



OverTheOCean
31st May 2010, 16:29
Hi,

I'm using a QlistWidget with Multiselection.... is that possible to get the indexes of selected items in the List, the selectedItems() return a list of selected items but l only need the indexes ( row selected).

thanks,

Michael

Tio
1st June 2010, 12:58
Hi friend
There's 2 methods in QListWidget: selectedItems and selectedIndexes. I guess that second one can help you
hugs :)

OverTheOCean
2nd June 2010, 06:13
this method is private but googling that l found a thread: "Retrieve selected indices from a QListWidget"

the solution is:
QModelIndexList indexes = listWidget->selectionModel()->selectedIndexes();
std::vector<int> indexList;
foreach(QModelIndex index, indexes)
indexList.push_back(index.row());

thanks,

Michael