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. Delete a row from gridLayout

Delete a row from gridLayout

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 11.5k 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
    deepakkakkeel
    wrote on last edited by
    #1

    Hi,

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

    Deepak

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

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

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

          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
          0
          • D Offline
            D Offline
            deepakkakkeel
            wrote on last edited by
            #5

            Ok. Thanks.

            Deepak

            1 Reply Last reply
            0
            • D Offline
              D Offline
              deepakkakkeel
              wrote on last edited by
              #6

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

                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
                0
                • D Offline
                  D Offline
                  deepakkakkeel
                  wrote on last edited by
                  #8

                  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
                  0

                  • Login

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