I've used Qt Designer to create a QWidget with a grid layout on it, containing checkboxes which are dynamically created in my code and correspond to a number in a file on my computer. When a file is changed on the machine, I need the layout to refresh with a number of check boxes equal to a new specified number in the file. I'm trying to use the following code:
//Refresh the layout
ui.TPCheckBoxLayout_G->invalidate();
ui.TPCheckBoxLayout_G->activate();
ui.TPCheckBoxLayout_G->update();
//Refresh the layout
ui.TPCheckBoxLayout_G->invalidate();
ui.TPCheckBoxLayout_G->activate();
ui.TPCheckBoxLayout_G->update();
QWidget::repaint();
To copy to clipboard, switch view to plain text mode
I call this code right after I delete all of the items from the layout, using the following code:
//Refresh checkboxes and buttons
int rowCount = ui.TPCheckBoxLayout_G->rowCount();
int columnCount = ui.TPCheckBoxLayout_G->columnCount();
for(int i=0; i<rowCount; i++)
{
for(int j=0; j<columnCount; j++)
{
//Clear the TP layout
ui.TPCheckBoxLayout_G->removeItem(ui.TPCheckBoxLayout_G->itemAtPosition(i,j));
delete ui.TPCheckBoxLayout_G->itemAtPosition(i,j);
}
}
}
//Refresh checkboxes and buttons
int rowCount = ui.TPCheckBoxLayout_G->rowCount();
int columnCount = ui.TPCheckBoxLayout_G->columnCount();
for(int i=0; i<rowCount; i++)
{
for(int j=0; j<columnCount; j++)
{
//Clear the TP layout
ui.TPCheckBoxLayout_G->removeItem(ui.TPCheckBoxLayout_G->itemAtPosition(i,j));
delete ui.TPCheckBoxLayout_G->itemAtPosition(i,j);
}
}
}
To copy to clipboard, switch view to plain text mode
However, after this code finished, the new boxes are present, but they appear over the old boxes, which don't exist in my code! My new stuff appears, but the old stuff doesn't go away. Any idea what I'm doing wrong?
Bookmarks