QRadioButton elements inside a QlistWidget
-
Hi @CodeVisio,
Yes it is possible- Create
new
QListWidgetItem
- Create
new
QRadioButton
- Use setItemWidget to add that RadioButton as a List item in
QListWidget
For eg:
QListWidget *list = new QListWidget(); QListWidgetItem *listitem = new QListWidgetItem(); list->setItemWidget(listitem,new QRadioButton("Radio Button"));
- Create
-
@CodeVisio
Use itemClicked(QListWidgetItem*) signal
and then for that item use itemWidget() method to access widget inside it. -
Thanks a lot @p3c0.
One more thing.
I can use QListWidget with check boxes (shown like QCheckBox) as elements inside it without
this approach list->setItemWidget( listitem, new QCheckBox() ) , while for QRadioBoxes I have to explicitly create those object before inserting them inside the list.
Is that a design choice? or is there a way to show QRadioBoxes inside the list as I can do with QCheckBoxes without creating them?Thanks again
-
@CodeVisio
For checkboxes I think you must have set Qt::ItemIsUserCheckable flag for QListWidgetItem. So there's a way to do so. But for radiobutton theres none and thus have to create the widget explicitly.Edit: Links