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. Derived QLayouts not owning added Items?
Forum Updated to NodeBB v4.3 + New Features

Derived QLayouts not owning added Items?

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

    Hi,

    qt-project.org writes

    bq. Note: The ownership of item is transferred to the layout, and it's the layout's responsibility to delete it.
    "here":http://qt-project.org/doc/qt-5.0/qtwidgets/qlayout.html#addItem

    @delete qWidget->layout()@

    where qWidget has a QGridLayout

    doesn't delete items of the layout in the qWidget added via addWidget to the layout.

    How to do this?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexisdm
      wrote on last edited by
      #2

      Your derived QLayout should delete the items in its destructor, see the example there: http://qt-project.org/doc/qt-5.0/qtwidgets/layout.html#the-implementation-file-card-op-op-cpp

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

        derived was referring to Qts derived layouts. I use a QGridLayout. It does not delete its items. As deleting the layouts items myself has no effect, I wonder whether it's just display remnants as I'm seeing the new layouts items I set afterwards on top of the old layouts items in my qWidget. Something else to consider? Despite that, thank you for your answer!

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alexisdm
          wrote on last edited by
          #4

          It does delete the items, but the widgets are not the items, their position is controlled by them. So when you delete the layout, the widgets that it contained stay where they last were.

          You should delete the widgets manually and possibly recursively (if the layout contains other layouts), or delete the whole widget that contains the layout and recreate both.

          Or you could use "that trick":http://stackoverflow.com/questions/4857188/clearing-a-layout-in-qt/7082920#7082920 .

          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