Results 1 to 6 of 6

Thread: How to remove QListItems via button click?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2011
    Posts
    24
    Qt products
    Qt4
    Platforms
    Windows

    Default How to remove QListItems via button click?

    Hi,

    I'm providing a QListWidget to get a list of custom values from the user as shown in the figure. The '+' is for adding & '-' is for removing item. To remove item user have to click an item on the list and the click '-' button. But this seems not working. I'm not sure whether I'm using the correct signals to achive this. Please help.

    list.png

    The '-' enabled when user selects an item.

    But click on '-' button do not remove the item from list. I'm keeping the currently selected item in a public variable to pass on remove method.


    Qt Code:
    1. //Signals
    2. connect(btnRemove, SIGNAL(clicked()), this, SLOT(RemoveFromList()));
    3. connect(lstList,SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(OnItemSelected(QListWidgetItem*)));
    4.  
    5.  
    6. //Slots
    7. void Designer::OnItemSelected( QListWidgetItem* item )
    8. {
    9. if ( item != NULL )
    10. {
    11. btnRemove->setEnabled(true);
    12. p_CurrentItem = item; //this holds the user clicked item
    13. }
    14. }
    15.  
    16. void Designer::RemoveFromList()
    17. {
    18. if ( p_CurrentItem != NULL )
    19. lstList->removeItemWidget(p_CurrentItem); //this don't remove the item, it stay in the list
    20.  
    21. if ( !lstList->count() )
    22. btnRemove->setEnabled(false);
    23. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Lykurg; 21st September 2011 at 09:36. Reason: missing [code] tags

Similar Threads

  1. Remove max,min button on a QMainWindow
    By Krish_ng in forum Qt Programming
    Replies: 9
    Last Post: 3rd August 2012, 13:36
  2. Replies: 2
    Last Post: 26th April 2011, 11:44
  3. how to remove tab with closable button.
    By ishkabible in forum Newbie
    Replies: 8
    Last Post: 20th September 2010, 02:03
  4. How can I know which button click.
    By electronicboy in forum Qt Programming
    Replies: 10
    Last Post: 4th October 2009, 14:27
  5. Remove restore button
    By vermarajeev in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2007, 13:29

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.