removing items QTreeWidget
Hey all,
Im using QTreeWidget and a QList to display some create items from user-input text.
code below:
Code:
QList<QTreeWidgetItem *> items;
repoList->insertTopLevelItems(0, items); //repoList= my QTreeWidget
now i have a remove button that when the user clicks it i want it to remove the currently selected item.
using the following code, items from the QTreeWidget are removed but not the one ive clicked! ("!?!WTF...)
Code:
int x = items.indexOf(repoList->currentItem());
repoList->takeTopLevelItem(x);
Ive also tried the following with no luck:
Code:
//with the following 2, the program compiles fine but nothing happens when i choose an item and click the remove button.
repoList->selectedItems().removeAt(x);
repoList->currentItem()->takeChild(x);
//i get a bunch of errors using the following one...
repoList->selectedItems().removeAll(repoList->currentItem()->text(0));
anyways, thank you for your time, and please help :_)
Re: removing items QTreeWidget
come on mates any help would be appriciated i have to manage this one way or another... :)
Re: removing items QTreeWidget
I tried this with a widget composed of a treewidget and a button.
When you push the button, it will delete the item selected in the treewidget
See if this works for you :
Code:
{
setupUi(this); // Just a treewidget and a button
QList<QTreeWidgetItem *> items;
for(int ii=0;ii<20;ii++)
{
}
treeWidget->insertTopLevelItems(0, items);
connect(DeleteSelected,SIGNAL(clicked()),this,SLOT(OnDeleteIt()));
treeWidget->setCurrentItem(items.at(0));
}
void A_Zfun::OnDeleteIt()
{
if(!item)return;
int x = treeWidget->indexOfTopLevelItem(item);
if(x >= 0 && x < treeWidget->topLevelItemCount())
{
item = treeWidget->takeTopLevelItem(x);
if(item)delete item;
}
}
Re: removing items QTreeWidget
This worked for me.
Code:
if(item)
delete item->parent()->takeChild(item->parent()->indexOfChild(item));