Qt Forum

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

    Removing and adding cells in a QGridLayout

    General and Desktop
    2
    2
    494
    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.
    • N
      nefarious last edited by

      I am trying to build a panel that uses a grid layout. To test the idea I build a QWidget and a QGridLayout for the QWidget. After I add the 20 elements, I want to remove these elements and replace them with 20 others. The code I use to replace them is:

              int index = mCurrentTab * mTabSize;
      
              //remove(mGridLayout, -1, 0, false);
              //mGridLayout->setColumnMinimumWidth(0, 0);
              //mGridLayout->setColumnStretch(0, 0);
      
              for (int i = 0; i < mTabSize; i++)
              {
                  QMicrophoneCtrl* mCtrl = mMicrophones.at(index +i);
                  qDebug() << "Remove: " << mCtrl->getMicrophoneIndex();
                  mGridLayout->removeWidget(mCtrl);
              }
              mCurrentTab = tab;
              index = mCurrentTab * mTabSize;
              for (int i = 0; i < mTabSize; i++)
              {
                  QMicrophoneCtrl* mCtrl = mMicrophones.at(index + i);
                  qDebug() << "Add: " << mCtrl->getMicrophoneIndex();
                  mGridLayout->addWidget(mCtrl, i, 0);
              }
      

      The net effect is that the new cells are written over the old cells and depending on the size of the new cell I can see both the old cell and the new cell. Is there a reason this won't work.

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @nefarious last edited by

        @nefarious You only remove old widgets from layout, you do not delete them. Maybe that is the reason: the old widgets are still shown at the same location they were before?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

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