Results 1 to 7 of 7

Thread: a simple question .how to delete a treewidgetitem

  1. #1
    Join Date
    Jan 2006
    Posts
    6
    Thanks
    1

    Wink a simple question .how to delete a treewidgetitem

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Angry Re: a simple question .how to delete a treewidgetitem

    Quote Originally Posted by Alina
    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?
    Qt Code:
    1. //TIP: Following code is only fabricated by looking at the docs, i have not tested it.
    2. if(treeWidget->currentItem() && !treeWidget->currentItem()->parent()){
    3. delete treeWidget->takeTopLevelItem(treeWidget->indexOfTopLevelItem(treeWidget->currentItem()));
    4. }else if(treeWidget->currentItem() && treeWidget->currentItem()->parent()){
    5. delete treeWidget->currentItem()->parent()->takeChild(treeWidget->currentItem()->parent()->indexOfChild(treeWidget->currentItem());
    6. }
    To copy to clipboard, switch view to plain text mode 

    One this is done, QTreeWidget should update it accordingly.

    Hope this works

  3. #3
    Join Date
    Jan 2006
    Posts
    6
    Thanks
    1

    Default Re: a simple question .how to delete a treewidgetitem

    Quote Originally Posted by yogeshm02
    Qt Code:
    1. //TIP: Following code is only fabricated by looking at the docs, i have not tested it.
    2. if(treeWidget->currentItem() && !treeWidget->currentItem()->parent()){
    3. delete treeWidget->takeTopLevelItem(treeWidget->indexOfTopLevelItem(treeWidget->currentItem()));
    4. }else if(treeWidget->currentItem() && treeWidget->currentItem()->parent()){
    5. delete treeWidget->currentItem()->parent()->takeChild(treeWidget->currentItem()->parent()->indexOfChild(treeWidget->currentItem());
    6. }
    To copy to clipboard, switch view to plain text mode 

    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() or
    currentitem() ,both hava no return . i want to delete a clicked treewidetitem ,but i do not
    know how to get it.

  4. #4
    Join Date
    Jan 2006
    Location
    Russia
    Posts
    50
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a simple question .how to delete a treewidgetitem

    Quote Originally Posted by Alina
    how can a treewidget get the currentItem? when click a item ,I use selecteditems() or
    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:
    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.

  5. #5
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: a simple question .how to delete a treewidgetitem

    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.

    Quote Originally Posted by Mad Max
    PS. yogeshm02, I think here there is need to reformat the example code to more suitable kind.
    I wanted to pack-up in as few lines as possible.

  6. #6
    Join Date
    Jan 2006
    Posts
    6
    Thanks
    1

    Default Re: a simple question .how to delete a treewidgetitem

    Quote Originally Posted by yogeshm02
    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.
    Thank your help !
    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.

  7. #7
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: a simple question .how to delete a treewidgetitem

    You can sublass QTreeWidget and reinplement keyPressEvent ( QKeyEvent * )


    or..try use eventFilter() for main widget
    a life without programming is like an empty bottle

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.