Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QRadioButton elements inside a QlistWidget
I'm a new QT developer.
What I'd like to have as end result is a QListWidget where the list's items are QRadioButtons.
Is that possible? And if it is, how could I implement that? Are there any examples to look from?
Yes it is possible
- Use setItemWidget to add that RadioButton as a List item in
QListWidget *list = new QListWidget(); QListWidgetItem *listitem = new QListWidgetItem(); list->setItemWidget(listitem,new QRadioButton("Radio Button"));
thank you for the answer.
How about the click notifications? How can I be notified about the user click?
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?
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.