Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Problem removing widget from a layout

    Mobile and Embedded
    6
    7
    4083
    Loading More Posts
    • 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
      mmesarina last edited by

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

      extLayout->removeWidget(treeWidget);
      @

      Do I need to do something extra?

      thanks

      -malena

      1 Reply Last reply Reply Quote 0
      • W
        wladek last edited by

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

        1 Reply Last reply Reply Quote 0
        • G
          giesbert last edited by

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

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply Reply Quote 0
          • J
            jorj last edited by

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

            1 Reply Last reply Reply Quote 0
            • G
              giesbert last edited by

              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.

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply Reply Quote 0
              • A
                andre last edited by

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

                1 Reply Last reply Reply Quote 0
                • Z
                  ZapB last edited by

                  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?

                  Nokia Certified Qt Specialist
                  Interested in hearing about Qt related work

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post