⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

Problem removing widget from a layout

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


    Do I need to do something extra?



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

  • What do you expect to happen and what happens?
    The widget will not be deleted and not be invisible.

  • you could try setting the widgets parent to 0, or as wladek says, if you do not need it, delete it.

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

  • Or, if you do need it again (later on), simply hide the widget instead of removing it from the layout.

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

Log in to reply