I have a treewidget in a dock window . i want to know how can i delete the activated treewidgetitem,and then show the new treewidget in dock?
Printable View
I have a treewidget in a dock window . i want to know how can i delete the activated treewidgetitem,and then show the new treewidget in dock?
Quote:
Originally Posted by Alina
Code:
//TIP: Following code is only fabricated by looking at the docs, i have not tested it. if(treeWidget->currentItem() && !treeWidget->currentItem()->parent()){ delete treeWidget->takeTopLevelItem(treeWidget->indexOfTopLevelItem(treeWidget->currentItem())); }else if(treeWidget->currentItem() && treeWidget->currentItem()->parent()){ delete treeWidget->currentItem()->parent()->takeChild(treeWidget->currentItem()->parent()->indexOfChild(treeWidget->currentItem()); }
One this is done, QTreeWidget should update it accordingly.
Hope this works
how can a treewidget get the currentItem? when click a item ,I use selecteditems() orQuote:
Originally Posted by yogeshm02
currentitem() ,both hava no return . i want to delete a clicked treewidetitem ,but i do not
know how to get it.
:) This method do exist, I assure you:Quote:
Originally Posted by Alina
http://doc.trolltech.com/4.1/qtreewi...ml#currentItem
PS. yogeshm02, I think here there is need to reformat the example code to more suitable kind.
Do not just try to use the code given by me. Try to understand what is being done, and then you would have no questions. ;) Refer to qt docs.
I wanted to pack-up in as few lines as possible. :cool:Quote:
Originally Posted by Mad Max
Thank your help !Quote:
Originally Posted by yogeshm02
now I know your code about how to delete a treewidgetitem. but now my question is
how can I get the treewidgetitem which the mouse has clicked?
I just want to realize the follow operation: click a treewidgetitem and then press a delete button to delete the clicked item.
You can sublass QTreeWidget and reinplement keyPressEvent ( QKeyEvent * )
:rolleyes:
or..try use eventFilter() for main widget