12
votes

QListWidget::selectedItems returns a list of QListWidgetItem, but the only function for removing an item that I found is takeItem, which accepts only indexes, and selectedIndexes function is protected.

3

3 Answers

25
votes

Try

qDeleteAll(listWidget->selectedItems());
3
votes

Iterate through the SelectedItemsList:

QList<QListWidgetItem *> itemList = widget->selectedItems();
for (int i=0; i<itemList.size(); i++) {
     widget->takeItem(widget->indexFromItem(itemList[i]));
}

I think

widget->removeItemWidget(itemList[i]);

may also work

0
votes

ui->listWidget->clear(); will do asof qt5