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. [SOLVED]How to remove a layout from a QWidget?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 19.7k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    b1gsnak3
    wrote on last edited by
    #1

    Hello.. I am trying to remove a layout from a qwidget and set a new layout... Tried with
    @widget->layout()->deleteLater();@

    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

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #2

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

      http://anavi.org/

      1 Reply Last reply
      0
      • B Offline
        B Offline
        b1gsnak3
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

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

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

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • B Offline
            B Offline
            b1gsnak3
            wrote on last edited by
            #5

            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?

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

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

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0

              • Login

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