Qt Forum

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

    Delete a row from gridLayout

    General and Desktop
    2
    8
    10743
    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
      deepakkakkeel last edited by

      Hi,

      Does anyone know how to delete a row from gridlayout. The row int the gridlayout contains widgets.

      Deepak

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

        This should do what you want:
        @
        QGridLayout* gridLayout;
        for(int c = 0; c < gridLayout->columnCount(); ++c)
        {
        QLayoutItem* item = gridLayout->itemAtPosition( row, c );
        QWidget* itemWIdget = item->widget();
        if( itemWidget )
        {
        gridLayout->removeWidget(itemWidget);
        delete itemWidget; //not sure if you want that?
        }
        }
        @

        --- 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
          deepakkakkeel last edited by

          Hi,

          Thanks .I could do deletion.
          But the row count of gridLayout is not decreasing. When i print the row count of gridLayout before deletion and after deletion they are same. May i know why is it?

          Deepak

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

            because that's the concept/implementation of QGridLayout class.
            You must explicitly specify the row and column when you add a item. And it will remain at it's position no matter if a preceding widget was removed, the grid itself stays the same.

            --- 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
              deepakkakkeel last edited by

              Ok. Thanks.

              Deepak

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

                hi,

                Is there any method to clear all the elements of gridlayout. A single line command as we clear a Qlist with the clear command.

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

                  no i am aware of... but removing all widgets form a QGridLayout is even simplier:
                  @
                  while( gridLayout->count() ) {
                  QWidget* widget = gridLayout->itemAt(0)->widget();
                  if( widget ) {
                  layout->removeWidget(widget);
                  delete widget;
                  }
                  }
                  @

                  --- 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
                    deepakkakkeel last edited by

                    But if we delete like the above, the row count of grid layout doesnot decrease. Is there any where when i delete the elements from a row of the gridlayout and the row count of the gridlayout also decrease.

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