klnusbaum
22nd May 2008, 19:50
I'm trying to dynamically create QComboBoxes and QLabels during run time based on the users input. Example: if the users enters 3, my program displays 3 comobboxes and 3 labels. If they then type in 2, my program will then display only 2 comboboxes and 2 labels. When ever the user changes the number of comboboxes and labels this function is called (numOfSurfaces is the user input that the number of comboboxes and labels depend on):
for(int row=0; row<surf_typeGrid->rowCount(); row++)
{
surf_typeGrid->removeItem(surf_typeGrid->itemAtPosition(row,0));
surf_typeGrid->removeItem(surf_typeGrid->itemAtPosition(row,1));
}
int numOfSurfaces = (nwall_typeLine->displayText()).toInt();
for(int i=1; i<=numOfSurfaces; i++)
{
char surfLabel [15];
sprintf(surfLabel, "Surface %d", i);
surf_typeGrid->addWidget(new QLabel(surfLabel), i-1, 0);
surf_typeGrid->addWidget(new QComboBox(), i-1,1);
}
The problem is that when the user changes the number of comboboxes and labels, instead of deleting the old comboboxes and lables and displaying just the new ones, the program still displays the old comboxes and labels and just puts the new ones on top of them. How do I make sure the old comboboxes and labels get removed?
for(int row=0; row<surf_typeGrid->rowCount(); row++)
{
surf_typeGrid->removeItem(surf_typeGrid->itemAtPosition(row,0));
surf_typeGrid->removeItem(surf_typeGrid->itemAtPosition(row,1));
}
int numOfSurfaces = (nwall_typeLine->displayText()).toInt();
for(int i=1; i<=numOfSurfaces; i++)
{
char surfLabel [15];
sprintf(surfLabel, "Surface %d", i);
surf_typeGrid->addWidget(new QLabel(surfLabel), i-1, 0);
surf_typeGrid->addWidget(new QComboBox(), i-1,1);
}
The problem is that when the user changes the number of comboboxes and labels, instead of deleting the old comboboxes and lables and displaying just the new ones, the program still displays the old comboxes and labels and just puts the new ones on top of them. How do I make sure the old comboboxes and labels get removed?