PDA

View Full Version : delete QListWidgetItem in QListWidget



sophister
10th May 2009, 13:57
Hi:
I have add some QListWidgetItem into a QListWidget through the following codes, and the QListWidgetItem contains both QIcon and QSrting like this:

ui->listWidget->addItem(new QListWidgetItem(icon, fileInfo.baseName()));
ui->listWidget->setIconSize(QSize(40, 40)); //设置图标大小

But when I delete the QListWidgetItem in the QListWidget, I only know the QString of the QListWidgetItem to be deleted, and I use the following:

QListIterator<QListWidgetItem*> i(ui->listWidget->findItems(QString("something"), Qt::MatchCaseSensitive));
while(i.hasNext())
{
// QListWidgetItem *temp = i.next();
ui->listWidget->removeItemWidget(i.next());
// delete temp;
}
unfortunately I failed.
Do some guys know how to delete them?
Thanks!

sophister
10th May 2009, 16:52
I answer myself in case someone run into the same question.
well, I have made a mistake. I should use the condes which are commented to delete, and they work well.