sashoalm
sashoalm

Reputation: 79685

How do I remove all the selected items in a QListWidget?

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.

Upvotes: 12

Views: 13953

Answers (3)

Dravigon
Dravigon

Reputation: 73

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

Upvotes: 0

O.C.
O.C.

Reputation: 6829

Try

qDeleteAll(listWidget->selectedItems());

Upvotes: 25

Tobias Schlegel
Tobias Schlegel

Reputation: 3970

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

Upvotes: 3

Related Questions