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. QFormLayout , how to remove rows having widgets
Qt 6.11 is out! See what's new in the release blog

QFormLayout , how to remove rows having widgets

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 4.8k Views 3 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.
  • Pradeep KumarP Offline
    Pradeep KumarP Offline
    Pradeep Kumar
    wrote on last edited by
    #1

    Hi,

    I am using QFormLayout, i am dynamically adding QLabel and QComboBox, to the rows using addrow(); if i try to add , previous elements are also present, how to remove rows of previously added.

    for (int i = 1; i <= nrow; i++)
        {
            for (int j = 1; j <= ncol; j++)
            {
               QLabel *gridLabel = new QLabel ;
                gridLabel->setText(QString::number(i)) ;
    
                QComboBox *cb = new QComboBox;
                cb->addItems(camidList) ;
    
                m_pQFormLayoutGrid->addRow(gridLabel, cb);
            }
        }
    

    How to remove previous rows from m_pQFormLayoutGrid, when i try to add new rows?.

    Thanks,

    Pradeep Kumar
    Qt,QML Developer

    FlotisableF 1 Reply Last reply
    0
    • Pradeep KumarP Pradeep Kumar

      Hi,

      I am using QFormLayout, i am dynamically adding QLabel and QComboBox, to the rows using addrow(); if i try to add , previous elements are also present, how to remove rows of previously added.

      for (int i = 1; i <= nrow; i++)
          {
              for (int j = 1; j <= ncol; j++)
              {
                 QLabel *gridLabel = new QLabel ;
                  gridLabel->setText(QString::number(i)) ;
      
                  QComboBox *cb = new QComboBox;
                  cb->addItems(camidList) ;
      
                  m_pQFormLayoutGrid->addRow(gridLabel, cb);
              }
          }
      

      How to remove previous rows from m_pQFormLayoutGrid, when i try to add new rows?.

      Thanks,

      FlotisableF Offline
      FlotisableF Offline
      Flotisable
      wrote on last edited by
      #2

      @Pradeep-Kumar
      QFormLayout::removeRow may be a choice

      1 Reply Last reply
      1
      • Pradeep KumarP Offline
        Pradeep KumarP Offline
        Pradeep Kumar
        wrote on last edited by
        #3

        Hi,

        I didnt find removeRow() for QFormLayout?.

        Pradeep Kumar
        Qt,QML Developer

        1 Reply Last reply
        0
        • Venkatesh VV Offline
          Venkatesh VV Offline
          Venkatesh V
          wrote on last edited by
          #4

          Hi @Pradeep-Kumar

          declare QObjectList in header file.
          //In Header File

          QObjectList objectList;

          //In Function

          if(objectList.length()!=0){
          for(int item =0;item<objectList.length();item++){
          delete objectList(item);
          }
          objectList.clear();
          }
          for (int i = 1; i <= nrow; i++)
          {
          for (int j = 1; j <= ncol; j++)
          {
          QLabel *gridLabel = new QLabel ;
          gridLabel->setText(QString::number(i)) ;

                  QComboBox *cb = new QComboBox;
                  cb->addItems(camidList) ;
          
                  m_pQFormLayoutGrid->addRow(gridLabel, cb);
          

          objectList.append(gridLabel);
          objectList.append(cb);
          }
          }

          Try this.Above code may help you.

          FlotisableF 1 Reply Last reply
          3
          • Venkatesh VV Venkatesh V

            Hi @Pradeep-Kumar

            declare QObjectList in header file.
            //In Header File

            QObjectList objectList;

            //In Function

            if(objectList.length()!=0){
            for(int item =0;item<objectList.length();item++){
            delete objectList(item);
            }
            objectList.clear();
            }
            for (int i = 1; i <= nrow; i++)
            {
            for (int j = 1; j <= ncol; j++)
            {
            QLabel *gridLabel = new QLabel ;
            gridLabel->setText(QString::number(i)) ;

                    QComboBox *cb = new QComboBox;
                    cb->addItems(camidList) ;
            
                    m_pQFormLayoutGrid->addRow(gridLabel, cb);
            

            objectList.append(gridLabel);
            objectList.append(cb);
            }
            }

            Try this.Above code may help you.

            FlotisableF Offline
            FlotisableF Offline
            Flotisable
            wrote on last edited by
            #5

            @Pradeep-Kumar
            sorry, QFormLayout::removeRow is introduced in Qt 5.8
            @Venkatesh-V's method is a good choice

            by the way, @Venkatesh-V I think you don't need the if statement before the delete for, since the condition in for have test it

            1 Reply Last reply
            2
            • Pradeep KumarP Offline
              Pradeep KumarP Offline
              Pradeep Kumar
              wrote on last edited by
              #6

              Hi,

              @Venkatesh-V
              Thank you it worked.
              I was trying to remove Qformlayout items by taking itemAt().

              Thanks,

              Pradeep Kumar
              Qt,QML Developer

              1 Reply Last reply
              1
              • Venkatesh VV Offline
                Venkatesh VV Offline
                Venkatesh V
                wrote on last edited by
                #7

                @Flotisable
                for the first time of method execution ObjectList size will be 0, on that time delete obectList item will crash the program because of index out of range. so i am setting flag there.

                1 Reply Last reply
                2
                • Pradeep KumarP Offline
                  Pradeep KumarP Offline
                  Pradeep Kumar
                  wrote on last edited by
                  #8

                  Hi,

                  if(objectList.length()!=0)
                  {
                  for(int item =0;item<objectList.length();item++)
                  {
                  delete objectList.at(item);
                  }
                  objectList.clear();
                  }
                  

                  used the above line of code before adding to the QFormLayout.

                  It worked,
                  May be in 5.8 we can use QFormLayout::removeRow() i guess,
                  I will try in some while in 5.8 for QFormLayout.

                  Thanks @Venkatesh-V
                  @Flotisable ,

                  Thanks,

                  Pradeep Kumar
                  Qt,QML Developer

                  1 Reply Last reply
                  0
                  • Venkatesh VV Offline
                    Venkatesh VV Offline
                    Venkatesh V
                    wrote on last edited by
                    #9

                    @Pradeep-Kumar
                    If it works fine, mark it as solved.

                    1 Reply Last reply
                    2

                    • Login

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