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 selectedIndex开发者_运维问答es function is protected.
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
精彩评论