开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜