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. QScrollArea and QVBoxLayout issues with dynamically added widgets
QtWS25 Last Chance

QScrollArea and QVBoxLayout issues with dynamically added widgets

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k 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.
  • D Offline
    D Offline
    dryajov
    wrote on last edited by
    #1

    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
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @
      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
      0
      • D Offline
        D Offline
        dryajov
        wrote on last edited by
        #3

        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
        0

        • Login

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