Results 1 to 4 of 4

Thread: remove item from QListWidget

  1. #1
    Join Date
    Sep 2007
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Smile remove item from QListWidget

    Hello,
    I am trying to display simple string in QListWidget.
    I want to limit the size of item of QlistWidget.
    It is not possible to remove item. removeItemWidget function does not work.
    Any idea?
    Thanks

    I use following code.

    void SQLTest::UpdateList(QString receivedData)
    {
    ui.debugList->addItem(new QListWidgetItem(receivedData));
    ui.debugList->setCurrentItem(item);

    qDebug() << ui.debugList.count() ;
    if (ui.debugList->count() == 5){
    ui.debugList->removeItemWidget(ui.debugList->item(0));
    qDebug() << ui.debugList->count();
    }
    }
    Last edited by yushinee; 2nd October 2007 at 12:23.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: remove item from QListWidget

    If you don't have a widget set in the item, then there is nothing to remove. Try this instead:
    Qt Code:
    1. delete ui.debugList->item(0);
    To copy to clipboard, switch view to plain text mode 

  3. The following 2 users say thank you to wysota for this useful post:

    Naytheet (11th January 2013), yushinee (2nd October 2007)

  4. #3
    Join Date
    Jul 2007
    Location
    California, USA
    Posts
    62
    Thanks
    17
    Thanked 7 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: remove item from QListWidget

    The documentation says to remove an item, use takeItem but you are responsible for deleting that item yourself.

    Qt Code:
    1. QListWidgetItem* item = ui.debugList->takeItem(0);
    2. delete item;
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: remove item from QListWidget

    Yes, but you don't have to take() it, if you delete it, it is taken out automatically by the destructor.

  6. The following 5 users say thank you to wysota for this useful post:

    Charvi (23rd December 2015), markg85 (8th October 2010), Naraha (25th April 2012), ntp (2nd October 2007), ravas (18th March 2016)

Similar Threads

  1. QListWidget and selecting an item
    By invictus in forum Newbie
    Replies: 4
    Last Post: 19th June 2007, 11:59
  2. Replies: 1
    Last Post: 19th April 2007, 22:23
  3. Replies: 1
    Last Post: 24th August 2006, 11:44
  4. extract item from QListWidget
    By impeteperry in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2006, 19:41
  5. keypress while editing an item in QListWidget
    By Beluvius in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2006, 09:56

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.