I am working to create a GUI with Qt and C++.
I have create dynamically some couples of buddies (QLabel
+ QSpinBox
) in order to refresh the number of errors that my program makes in the last thousand round to my loop.
My code to create this:
if((num_fotos % 1000) == 0){
if(num_layouts < NUM_FAIL_COUNT){
for(int i = 0; i < (buffer->length()-1); i++){
sum_100_fallos += int(buffer->at(i));
}
QLabel * label_1000 = new QLabel();
label_1000->setText("Fallos 1000_" + QString::number(num_fotos/1000) + ": ");
label_1000->setMinimumHeight(24);
QSpinBox * spinBox_1000 = new QSpinBox();
//newElements->append(label_1000);
spinBox_1000->setReadOnly(true);
spinBox_1000->setRange(0, 1000);
spinBox_1000->setMinimumHeight(24);
new_layouts[num_layouts] = new QHBoxLayout;
//newElements->append(spinBox_1000);
new_layouts[num_layouts]->addWidget(label_1000);
new_layouts[num_layouts]->addWidget(spinBox_1000);
spinBox_1000->setValue(num_fallos_1000);
num_fallos_1000 = 0;
ui->verticalLayout_5->addLayout(new_layouts[num_layouts]);
num_layouts++;
}else{
aux = num_layouts % NUM_FAIL_COUNT;
delete new_layouts[aux];
for(int i = 0; i < (buffer->length()-1); i++){
sum_100_fallos += int(buffer->at(i));
}
QLabel * label_1000 = new QLabel();
label_1000->setText("Fallos 1000_" + QString::number(num_fotos/1000) + ": ");
label_1000->setMinimumHeight(24);
QSpinBox * spinBox_1000 = new QSpinBox();
//newElements->append(label_1000);
spinBox_1000->setReadOnly(true);
spinBox_1000->setRange(0, 1000);
spinBox_1000->setMinimumHeight(24);
new_layouts[aux] = new QHBoxLayout;
//newElements->append(spinBox_1000);
new_layouts[aux]->addWidget(label_1000);
new_layouts[aux]->addWidget(spinBox_1000);
spinBox_1000->setValue(num_fallos_1000);
num_fallos_1000 = 0;
ui->verticalLayout_5->addLayout(new_layouts[aux]);
num_layouts++;
}
}
NUM_FAIL_COUNT
is the numbers of (QLabels
+ QLineEdit
) to show simultaneously.
If there is less than NUM_FAIL_COUNT
, I create new layouts and add them to the view.
As you can see, this is what I am creating dynamically.
But, if there are more than NUM_FAIL_COUNT
, I want to remove the entire first layout, with its children in order to add the new one at the bottom.
What happens is that the first layout is removed, but not its children, overlapping the QLabel
+ QLineEdit
.
I have tried accessing to it by children()
call, with pointers, deleteLater()
, and trying to clearing layout previously to its deletion.
What am I thinking wrong? Thanks for your answer.