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.
To achieve the required functionality i.e. to cleaning the window or deleting all elements using Qlistwidget in Python, its clear() method is used.
QListWidget has a member named clear(). The docs for this method state: void QListWidget::clear () [slot] Removes all items and selections in the view. Warning: All items will be permanently deleted.
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
Try
qDeleteAll(listWidget->selectedItems());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With