Important: Please read the Qt Code of Conduct -

Dynamically creating checkboxes

  • Actually, i need to create checkboxes dynamically as per user requirements, so which one is the better approach, should i go for scroll area then create checboxes inside that or is there any better approach pls let me know.

  • Normally in these cases you don't need checkboxes but a checkable list like QListWidget

  • Lifetime Qt Champion

    as @VRonin saids a ListWidget with ItemIsUserCheckable is
    often a far better solution than scrollarea.

    QListWidgetItem* item = new QListWidgetItem("item", listWidget);
    item->setFlags(item->flags() | Qt::ItemIsUserCheckable); // set checkable flag
    item->setCheckState(Qt::Unchecked); // AND initialize check state ( not sure its 100% needed but i like to be sure :)

Log in to reply