I have a qgridlayout which consists of a grid 3 rows and X columns. It starts as one column. I then programatically add columns using "addWidget" adding to rows 0 and 1 in a new column. This works fine. I would like to then delete all the columns (except the first) then start over adding new columns the same way. I tried using "removeItem" but this does not seem to work.

Qt Code:
  1. //Add columns
  2. QGridLayout *layout = ui->gridlayout;
  3. Qlabel label, label2;
  4. QGraphicsView gv, gv2;
  5.  
  6. layout->addWidget(label1,0,1)
  7. layout->addWidget(gv1,1,1)
  8. layout->addWidget(label2,0,2)
  9. layout->addWidget(gv2,1,2)
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. //Remove columns
  2. QGridLayout *layout = ui->gridlayout;
  3.  
  4. layout->columnCount() // 3 as expected
  5.  
  6. layout->removeItem(layout->itemAtPosition(0,1)
  7. layout->removeItem(layout->itemAtPosition(1,1)
  8.  
  9. layout->columnCount() // Still 3, expecting 2
  10.  
  11. layout->removeItem(layout->itemAtPosition(0,2)
  12. layout->removeItem(layout->itemAtPosition(1,2)
  13.  
  14. layout->columnCount() // Still 3, expecting 1
To copy to clipboard, switch view to plain text mode