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.
//Signals
connect(btnRemove, SIGNAL(clicked()), this, SLOT(RemoveFromList()));
//Slots
{
if ( item != NULL )
{
btnRemove->setEnabled(true);
p_CurrentItem = item; //this holds the user clicked item
}
}
void Designer::RemoveFromList()
{
if ( p_CurrentItem != NULL )
lstList->removeItemWidget(p_CurrentItem); //this don't remove the item, it stay in the list
if ( !lstList->count() )
btnRemove->setEnabled(false);
}
//Signals
connect(btnRemove, SIGNAL(clicked()), this, SLOT(RemoveFromList()));
connect(lstList,SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(OnItemSelected(QListWidgetItem*)));
//Slots
void Designer::OnItemSelected( QListWidgetItem* item )
{
if ( item != NULL )
{
btnRemove->setEnabled(true);
p_CurrentItem = item; //this holds the user clicked item
}
}
void Designer::RemoveFromList()
{
if ( p_CurrentItem != NULL )
lstList->removeItemWidget(p_CurrentItem); //this don't remove the item, it stay in the list
if ( !lstList->count() )
btnRemove->setEnabled(false);
}
To copy to clipboard, switch view to plain text mode
Bookmarks