How to remove selected items from a QListWidget
?
I have tried write the following code, but it does not work.
QList<QListWidgetItem*> items = ui->listWidget->selectedItems(); foreach(QListWidgetItem item, items){ ui->listWidget->removeItemWidget(item); }
You may use this code to remove: QListWidgetItem *it = ui->listWidget->takeItem(ui->listWidget->currentRow()); delete it; Keep in mind that "takeItem" does not delete the object. Hi, friend, welcome devnet.
To remove items from the list, use takeItem() . The current item in the list can be found with currentItem() , and changed with setCurrentItem() . The user can also change the current item by navigating with the keyboard or clicking on a different item.
One way to remove item from QListWidget
is to use QListWidget::takeItem
which removes and returns the item :
QList<QListWidgetItem*> items = ui->listWidget->selectedItems(); foreach(QListWidgetItem * item, items) { delete ui->listWidget->takeItem(ui->listWidget->row(item)); }
Another way is to qDeleteAll
:
qDeleteAll(ui->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