Problem removing widget from a layout
-
wrote on 4 Apr 2011, 03:28 last edited by
Hi,
this seems like something that should just work, but it doesn't.
I have a layout and I want to remove a widget for which I have a pointer to and it is just not doing it.
I am using removeWidget(*widget) , like this:
@extLayout->removeWidget(treeWidget);
@Do I need to do something extra?
thanks
-malena
-
wrote on 4 Apr 2011, 06:11 last edited by
Hi mmesarina,
Is you interest in deleting the widget? From the docs of "QLayout":http://doc.qt.nokia.com/4.7-snapshot/qlayout.html#removeWidget seems that the widget still exists, and it is your responsibility to put in in another layout. Try adding it to a different layout, or if you don't need it anymore, just delete the pointer to this QWidget.
Hope this helps,
wladek -
wrote on 4 Apr 2011, 06:14 last edited by
What do you expect to happen and what happens?
The widget will not be deleted and not be invisible. -
wrote on 4 Apr 2011, 08:43 last edited by
you could try setting the widgets parent to 0, or as wladek says, if you do not need it, delete it.
-
wrote on 4 Apr 2011, 08:46 last edited by
setting the parent to 0 is not the best idea, because then you have a new top level window, and perhaps, that's not the expected behavior.
-
wrote on 4 Apr 2011, 08:47 last edited by
Or, if you do need it again (later on), simply hide the widget instead of removing it from the layout.
-
wrote on 4 Apr 2011, 12:05 last edited by
As others have said, the code you posted is sufficient to remove the widget from the layout. However it is not sufficient to hide it or delete it or reparent it or add it to another layout. And so the widget will still be visible. What are you trying to achieve?
1/7