How to change or detach layout of Widget?(+ or using private function)

  • first, i set the widget's layout,


    but i want to change the layout of widget, according to condition.


    they send the errormessage "~~already set the layout".

    how can i solve this problem?

    I find QWidget::takeLayout()
    but it was private, so i can use this function :(..... plz give me the solution..

  • Moderators

    @Mue22 Use layout() to get the current layout and delete it. Then remove all the widgets added inside it. After that set new layout using setLayout().

  • @p3c0
    thanks to your replay :)!!!
    i want to just change each layout....:(
    i want to just detach the layout from widget, and reuse to another widget..
    (if i use your solution, i can reuse layout1, 2... its correct?)
    ->(if i use your solution, i can't reuse layout1, 2... its correct?)

  • Moderators

    @Mue22 AFAIK to detach you will have to delete it and hence all the widgets inside it too. Then create new layout and then setLayout.

    i can reuse layout1, 2... its correct?

    No, since it is deleted.

  • @p3c0

    ah!! sorry sorry...i'm not freindly to english...:);;;;;
    i want to say that:
    if i use your solution, i can't reuse layout1, 2... its correct?


    it's so difficult problem...:(

  • Moderators

    @Mue22 Yes you can't. Since detaching requires deleting, new layout must be created to use again.

  • @p3c0

    Thanks to your kind replies!!!!

    i think, maybe i find another method....

Log in to reply

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