Important: Please read the Qt Code of Conduct -

[SOLVED]How to remove a layout from a QWidget?

  • Hello.. I am trying to remove a layout from a qwidget and set a new layout... Tried with

    and with

    @delete widget->layout();@

    but none of them worked.

    Thank you in advance.

    Qt 4.8.4 MSVC2008

    L.E. I did not copy and paste the code... I wrote it here in a hurry that is why I didn't have the layout()... In the code it is with ()... My mistake

  • Delete all widgets and child layouts owned by the layout before deleting it.

  • hmm well... I cannot do that... Because I need most of the items inside that layout... It basically changes 3 widgets... I'm thinking of trying with QStackedLayout but i would like to know if there is another way of doing this...

  • Moderators

    [quote author="b1gsnak3" date="1357636052"]
    [/quote]I believe you need to call the layout() function using parentheses:

    widget->layout () ->deleteLater();

  • Ok this is starting to get annoying... I used a qstackedlayout, however it gives me a layout only for the last item in the stack... I do not know why... Is it because I use the same objects in each widget?

  • Moderators

    [quote author="b1gsnak3" date="1357657479"]Is it because I use the same objects in each widget?[/quote]You can't share a widget between different layouts/widgets. If you add a widget to one layout, then add it to another layout, it will be removed from the first layout.

    So, to expand on leon.anavi's answer: Try moving your widgets to a new layout, delete the old layout, then apply the new layout to the parent widget.

Log in to reply