[ACCEPTED]-Adding list of check boxes in a single widget in Qt-qt

Accepted answer
Score: 12

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!

Score: 12

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.

Score: 0

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