June 3, 2011

henryxuv henryxuv
Lab Rat
46 posts

A question about QTreeWidget

 

I am using the SetItemWidget function of QTreeWidget. I new a widget and set it to one QTreeWidgetItem, After call removeItemWidget, If I need to delete widget. what does removeItemWidget do for me.

5 replies

June 3, 2011

cincirin cincirin
Ant Farmer
453 posts

This function make as it says … remove widget from item. So if you did not set a widget in item, nothing have to remove. If you want to remove item from tree, just delete it.

June 3, 2011

henryxuv henryxuv
Lab Rat
46 posts

cincirin wrote:
This function make as it says … remove widget from item. So if you did not set a widget in item, nothing have to remove. If you want to remove item from tree, just delete it.

  1. QTreeWidget treeWidget;
  2. QTreeWidgetItem *pOneItem = new QTreeWidgetItem;
  3. MyOwnWidget *pCustomWidget = new MyOwnWidget;
  4. treeWidget.SetItemWidget(pOneItem, 0, pCustomeWidget)
  5. treeWidget.RemoveItemWidget(pOneItem,0);
  6. treeWidget.clear()
  7.  
  8. //If I need to call those ?????If the clear and RemoveItemWidget function will release the memory automatically.
  9. delete pCustomWidget;
  10. delete pOneItem;

June 3, 2011

cincirin cincirin
Ant Farmer
453 posts

If you already call clear [doc.qt.nokia.com], you do not have to delete it. I’m not sure if you call removeItemWidget [doc.qt.nokia.com], your pCustomWidget will be deleted.

June 3, 2011

Andre Andre
Robot Herder
6393 posts

Easy enough to test though: set a breakpoint in the destructor of MyOwnWidget, and see if it gets called.

June 3, 2011

henryxuv henryxuv
Lab Rat
46 posts

Andre wrote:
Easy enough to test though: set a breakpoint in the destructor of MyOwnWidget, and see if it gets called.

Thank you Andre for you light.

 
  ‹‹ Sorry, total Qt newbe question...      How to set qml listview model in C++ ››

You must log in to post a reply. Not a member yet? Register here!