Results 1 to 5 of 5

Thread: QListWidgetItem remove an item

  1. #1
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QListWidgetItem remove an item

    Why can't i remove an item into a QListWidget an item?
    Qt Code:
    1. void regExp::deleteItem()
    2. {
    3. QList<QListWidgetItem *> listReSelected = ui.listWidgetRE->selectedItems();
    4. ui.labelOut->setText("Size: " + QString::number(listReSelected.size(), 10)); //print the correct vector size
    5. for (int i = 0; i < listReSelected.size(); ++i){
    6. ui.labelOut->setText("selected: " + listReSelected.at(i)->text()); //print the correct name
    7. ui.listWidgetRE->removeItemWidget(listReSelected.at(i)); //it doesn't work
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    removeItemWidget want a QListWidgetItem* and i'm passing it....

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidgetItem remove an item

    Which Qt version do you use? Have you tried "delete listReSelected.at(i);"?

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QListWidgetItem remove an item

    Are you mixing "items" and "item widgets"? Item widgets are widgets laid on top of items.
    J-P Nurmi

  4. The following user says thank you to jpn for this useful post:

    mattia (9th November 2007)

  5. #4
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    172
    Thanks
    39
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QListWidgetItem remove an item

    The widget that contains my item(listWidgetRE) is a QListWidget and ui.listWidgetRE->selectedItems(); returns a QListWidgetItem*, am i mixing them in a wrong way?
    Anyway your "delete listReSelected.at(i);" works, but if i'm making a mistake i'd like to know it thx
    I'm using Qt 4

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QListWidgetItem remove an item

    QListWidget is a widget which contains items, namely QListWidgetItems. QListWidgetItems are not widgets but just light items. One handles items (amongst others) with following methods:

    One can simply delete an item to remove it from QListWidget.

    In situations when you need to achieve something you cannot do with items, you have the possibility to place an individual widget on top of an item. These widgets are are called "item widgets". One accesses item widgets with following methods:
    J-P Nurmi

  7. The following 2 users say thank you to jpn for this useful post:

    foxyproxy (4th April 2008), gedgeck (31st October 2009)

Similar Threads

  1. Check Box problem
    By Seema Rao in forum Qt Programming
    Replies: 6
    Last Post: 30th November 2007, 19:32
  2. Replies: 1
    Last Post: 19th April 2007, 22:23
  3. Remove selected QListWidgetItem
    By xgoan in forum Newbie
    Replies: 7
    Last Post: 28th September 2006, 14:42
  4. QListWidget add QListWidgetItem
    By fellobo in forum Qt Programming
    Replies: 3
    Last Post: 20th February 2006, 19:37
  5. QSettings again ... how to remove array elements
    By Mike in forum Qt Programming
    Replies: 4
    Last Post: 11th January 2006, 08:58

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.