Qt Forum

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

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    QScrollArea and QVBoxLayout issues with dynamically added widgets

    General and Desktop
    2
    3
    1246
    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.
    • D
      dryajov last edited by

      Im running into a weird issue with dynamically added widgets to a QVBoxLayout contained inside a QScrollArea. If I add the widgets it works as expected, however after all widgets are removed, there are still some left overs on the screen. Is this a bug? Can someone else reproduce it?

      "Screenshot":http://i.stack.imgur.com/5yK8p.png

      "Here is a small project to reproduce it":https://github.com/dryajov/testscrollarea.git

      1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators last edited by

        @
        delete ui->verticalLayout->takeAt(0);
        @
        is not enough to also remove the widgets.

        You should do this:
        @
        QLayoutItem *child;
        while ((child = layout->takeAt(0)) != 0)
        {
        delete child->widget();
        delete child;
        }
        @

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply Reply Quote 0
        • D
          dryajov last edited by

          That seems to have done it. The important bit seems to be:

          delete child->widget;

          Because I did try deleting just the LayoutItem in my work project.

          Thanks!

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