QListWidget 删除选中项目

时间:2021-04-26 07:23:23
void MainWindow::on_action_Del_triggered()
{
QList<QListWidgetItem*> selectedItems = ui->listWidget->selectedItems();
if (selectedItems.count() > 0)
{
if (QMessageBox::Yes == QLibX::QMessageBoxEx::GetInstance()->question(this,"删除确认",
QString("确认删除 %1 个项目?").arg(QString::number(selectedItems.count())),QMessageBox::Yes|QMessageBox::No,QMessageBox::Yes))
{
foreach (QListWidgetItem* var, selectedItems) {
ui->listWidget->removeItemWidget(var);
selectedItems.removeOne(var);
delete var;
}
}
}
}