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.

Answers


Try

qDeleteAll(listWidget->selectedItems());

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


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


Need Your Help

OData "where ID in list" query

linq collections filter odata

I have an OData service where I'm trying to filter by a list of IDs; the SQL equivalent would be something like:

ASP.NET MVC optional field being treated as required

asp.net-mvc asp.net-mvc-3

I have this field that for some reason when I click on submit, gets a validation message that the field is required.