[ACCEPTED]-Adding list of check boxes in a single widget in Qt-qt
Well you could indeed use a QListWidget
with checkable 3 items (see void QListWidgetItem::setFlags
, or use a QScrollArea
containing a QWidget
where 2 you would dynamically add QCheckBoxes
. The choice is 1 up to you!
Use QListWidget for the area.
QStringList itemLabels= getLabels();
QStringListIterator it(itemLabels);
while (it.hasNext())
{
QListWidgetItem *listItem = new QListWidgetItem(it.next(),listWidget);
listItem->setCheckState(Qt::Unchecked);
ui->listWidget->addItem(listItem);
}
this will 3 automatically make all the elements checkable 2 and when the list increases it will enable 1 scrolling.
An alternative to QListWidget is a QScrollArea 5 with a widget inside, which has a QVBoxLayout. To 4 that layout, you can add QCheckboxes dynamically. You 3 must call updateGeometry() after adding 2 a new widget, otherwise the UI might not 1 update if already visible.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.