Results 1 to 2 of 2

Thread: delete QListWidgetItem in QListWidget

  1. #1
    Join Date
    Apr 2009
    Location
    China
    Posts
    127
    Thanks
    30
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question delete QListWidgetItem in QListWidget

    Hi:
    I have add some QListWidgetItem into a QListWidget through the following codes, and the QListWidgetItem contains both QIcon and QSrting like this:
    Qt Code:
    1. ui->listWidget->addItem(new QListWidgetItem(icon, fileInfo.baseName()));
    2. ui->listWidget->setIconSize(QSize(40, 40)); //设置图标大小
    To copy to clipboard, switch view to plain text mode 

    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:
    Qt Code:
    1. QListIterator<QListWidgetItem*> i(ui->listWidget->findItems(QString("something"), Qt::MatchCaseSensitive));
    2. while(i.hasNext())
    3. {
    4. // QListWidgetItem *temp = i.next();
    5. ui->listWidget->removeItemWidget(i.next());
    6. // delete temp;
    7. }
    To copy to clipboard, switch view to plain text mode 
    unfortunately I failed.
    Do some guys know how to delete them?
    Thanks!

  2. #2
    Join Date
    Apr 2009
    Location
    China
    Posts
    127
    Thanks
    30
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: delete QListWidgetItem in QListWidget

    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.

Similar Threads

  1. QListWidget and QListWidgetItem
    By Noxxik in forum Qt Programming
    Replies: 5
    Last Post: 3rd August 2011, 10:59
  2. Replies: 4
    Last Post: 19th February 2009, 12:10
  3. c++, placement delete upon exception
    By stinos in forum General Programming
    Replies: 6
    Last Post: 31st October 2006, 16:38
  4. QListWidget + Delete Key
    By bpetty in forum Newbie
    Replies: 5
    Last Post: 16th August 2006, 21:38
  5. QListWidget add QListWidgetItem
    By fellobo in forum Qt Programming
    Replies: 3
    Last Post: 20th February 2006, 20:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.