How can I add dynamic checkboxes to scrollareaWidget?
-
Hi,
I would to add many checkboxes to a scroll area.
I wrote this script, but don't work.
@QCheckBox *dynamicCheckBox = new QCheckBox();
long YSpacer = -25;
for (int count = 0; count < QVSideList->size(); ++count)
{
YSpacer += 26;
dynamicCheckBox->setObjectName ("dynamicCheckBox" + QString(count));
dynamicCheckBox->setCheckable (true);
dynamicCheckBox->setChecked (true);
int TextWidth = QVSideList->at (count).File.size ();
dynamicCheckBox->setGeometry (10, YSpacer, TextWidth, 17);
dynamicCheckBox->setText (QVSideList->at (count).File);
//layout ()->addWidget (dynamicCheckBox);
ui->FolderSync::scrollAreaWidgetContents->layout ()->addWidget (dynamicCheckBox);
}@ -
You only have one QCheckBox you're working with. (One call to new QCheckBox() )
In your for loop, you're just fiddling around with that same widget instance over and over.
If you want multiple check boxes, you'll have to call new for each one inside of your loop.
-
@long YSpacer = -25;
for (int count = 0; count < QVSideList->size(); ++count)
{
YSpacer += 26;
QCheckBox *dynamicCheckBox = new QCheckBox();
dynamicCheckBox->setObjectName ("dynamicCheckBox" + QString(count));
dynamicCheckBox->setCheckable (true);
dynamicCheckBox->setChecked (true);
int TextWidth = QVSideList->at (count).File.size ();
dynamicCheckBox->setGeometry (10, YSpacer, TextWidth, 17);
dynamicCheckBox->setText (QVSideList->at (count).File);
//layout ()->addWidget (dynamicCheckBox);
ui->FolderSync::scrollAreaWidgetContents->layout ()->addWidget (dynamicCheckBox); //this line
}
}@Everything is okay, but I get segmentation fault on the last line.