开发者

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

开发者 https://www.devze.com 2023-03-27 04:30 出处:网络
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 functi

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号