Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I empty a QListWidget without having it delete all of the QListItemWidgets it contains?

Tags:

qt

qlistwidget

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.

How can I avoid all of the items being permanently deleted? I just want to clear the lists contents so that I can re-populate it with different data (however, I want to keep the data that was in it to display again if the user chooses to do so).

like image 806
finiteloop Avatar asked Mar 07 '12 01:03

finiteloop


1 Answers

QListWidget::takeItem

while(listwidget->count()>0)
{
  listwidget->takeItem(0);//handle the item if you don't 
                          //have a pointer to it elsewhere
}
like image 169
tmpearce Avatar answered Sep 17 '22 22:09

tmpearce