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.



  • 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.



  • [quote author="cincirin" date="1307082603"]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.[/quote]
    @
    QTreeWidget treeWidget;
    QTreeWidgetItem *pOneItem = new QTreeWidgetItem;
    MyOwnWidget *pCustomWidget = new MyOwnWidget;
    treeWidget.SetItemWidget(pOneItem, 0, pCustomeWidget)
    treeWidget.RemoveItemWidget(pOneItem,0);
    treeWidget.clear()

    //If I need to call those ?????If the clear and RemoveItemWidget function will release the memory automatically.
    delete pCustomWidget;
    delete pOneItem;
    @



  • If you already call "clear":http://doc.qt.nokia.com/latest/qtreewidget.html#clear, you do not have to delete it. I'm not sure if you call "removeItemWidget":http://doc.qt.nokia.com/latest/qtreewidget.html#removeItemWidget, your pCustomWidget will be deleted.



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



  • [quote author="Andre" date="1307089960"]Easy enough to test though: set a breakpoint in the destructor of MyOwnWidget, and see if it gets called.[/quote]
    Thank you Andre for you light.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.