In this example the text of the labels are re-drawn and overlay each other when pressing the button. Is there a possibility to clear the layout mGridLayout before calling Initialize()? Or is the only solution to save the labels globally and simply set the text instead of creating them each time?
Code:
{ // test input mTermName.append("term 1"); mTermName.append("term 2"); mValues.append(1.23); mValues.append(3.4322); Initialize(); // initializes mGridLayout with its content mMainLayout->addLayout(mGridLayout, 0, 0); Q_ASSERT(connect(btn, SIGNAL(clicked()), this, SLOT(slotPressed()))); mMainLayout->addWidget(btn, 1, 0); setLayout(mMainLayout); } void MyDialog::slotPressed() { mValues[0] = 2.5; Initialize(); } void MyDialog::Initialize() { int nbrTerms = 2; int row = 1; for(int i=0; i<nbrTerms; i++) { double termValue = mValues[i]; mGridLayout->addWidget(nameLabel, row, 1); mGridLayout->addWidget(termValueLabel,row, 2); row++; } }