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. Cleaning QFormLayout
Qt 6.11 is out! See what's new in the release blog

Cleaning QFormLayout

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 4.3k Views 2 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.
  • ZoptuneZ Offline
    ZoptuneZ Offline
    Zoptune
    wrote on last edited by Zoptune
    #1

    Hi,

    I'm using a QFormLayout to display rows of QString and QSpinBox
    I need to clean the content of my layout to add new row.

    I have tried things like removeItem(itemAt()) but it's not working, i still have some labels superposition.

    Thx

    EDIT : I have also tried takeAt(0) but i have error like : QFormLayout::takeAt: Invalid index 0

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      The layout owns the widgets so u should use
      takeAt to transfer ownership back if you plan on deleting the
      "row" widgets u remove.

      try this for clean all.

      void clearLayout(QLayout *layout) 
      {
          if (layout) {
              while(layout->count() > 0){
                  QLayoutItem *item = layout->takeAt(0);
                  delete item->widget();
                  delete item;
              }
          }
      }
      
      1 Reply Last reply
      2
      • ZoptuneZ Offline
        ZoptuneZ Offline
        Zoptune
        wrote on last edited by
        #3

        Ha ok !

        I have also tried to delete the item but i thought i was automatically deleting the widget.

        Thx :)

        mrjjM 1 Reply Last reply
        0
        • ZoptuneZ Zoptune

          Ha ok !

          I have also tried to delete the item but i thought i was automatically deleting the widget.

          Thx :)

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Zoptune

          One would assume that QLayoutItem owns the widget and deletes it.
          I never tested it :)

          Sounds like it wont ?

          ZoptuneZ 1 Reply Last reply
          0
          • mrjjM mrjj

            @Zoptune

            One would assume that QLayoutItem owns the widget and deletes it.
            I never tested it :)

            Sounds like it wont ?

            ZoptuneZ Offline
            ZoptuneZ Offline
            Zoptune
            wrote on last edited by
            #5

            @mrjj
            Tried by adding comment to : delete item->widget();

            Didn't work

            mrjjM 1 Reply Last reply
            1
            • ZoptuneZ Zoptune

              @mrjj
              Tried by adding comment to : delete item->widget();

              Didn't work

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Zoptune
              Ok, thanks.
              so QLayoutItem dont own the widget, it really is the layout. :)

              1 Reply Last reply
              1
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

                There's currently no way to directly remove or remove + delete content of a QFormLayout. But there's a work in progress patch for that.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1

                • Login

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