Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to change or detach layout of Widget?(+ or using private function)
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 2.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mue22
    wrote on 14 May 2015, 06:18 last edited by Mue22
    #1

    first, i set the widget's layout,

    ui->widget1->setLayout(layout1);
    ui->widget2->setLayout(layout2);

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

    ui->widget1->setLayout(layout2);
    ui->widget2->setLayout(layout1);

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

    i can't use english well...

    P 1 Reply Last reply 14 May 2015, 07:04
    0
    • M Mue22
      14 May 2015, 06:18

      first, i set the widget's layout,

      ui->widget1->setLayout(layout1);
      ui->widget2->setLayout(layout2);

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

      ui->widget1->setLayout(layout2);
      ui->widget2->setLayout(layout1);

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

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 14 May 2015, 07:04 last edited by
      #2

      @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().

      157

      M 1 Reply Last reply 14 May 2015, 07:13
      0
      • P p3c0
        14 May 2015, 07:04

        @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().

        M Offline
        M Offline
        Mue22
        wrote on 14 May 2015, 07:13 last edited by Mue22
        #3

        @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?)

        i can't use english well...

        P 1 Reply Last reply 14 May 2015, 07:20
        0
        • M Mue22
          14 May 2015, 07:13

          @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?)

          P Offline
          P Offline
          p3c0
          Moderators
          wrote on 14 May 2015, 07:20 last edited by
          #4

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

          157

          M 1 Reply Last reply 14 May 2015, 07:23
          0
          • P p3c0
            14 May 2015, 07:20

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

            M Offline
            M Offline
            Mue22
            wrote on 14 May 2015, 07:23 last edited by
            #5

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

            ...haha.

            it's so difficult problem...:(

            i can't use english well...

            P 1 Reply Last reply 14 May 2015, 07:28
            0
            • M Mue22
              14 May 2015, 07:23

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

              ...haha.

              it's so difficult problem...:(

              P Offline
              P Offline
              p3c0
              Moderators
              wrote on 14 May 2015, 07:28 last edited by
              #6

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

              157

              M 1 Reply Last reply 14 May 2015, 07:31
              0
              • P p3c0
                14 May 2015, 07:28

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

                M Offline
                M Offline
                Mue22
                wrote on 14 May 2015, 07:31 last edited by
                #7

                @p3c0

                Thanks to your kind replies!!!!

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

                i can't use english well...

                1 Reply Last reply
                0

                1/7

                14 May 2015, 06:18

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved