As you may have read, there are two approaches to achieve what you want.
- The most flexible one: use a
QListView
, implement a new delegate and a model if necessary. - Keep using the classic item-based interface (
QListWidget
) and change the item's widgets either by sub-classingQListWidgetItem
or callingQListWidgetItem::setItemWidget
.
Since the question points towards the second one, I'll try to provide the simplest item-based solution.
The following piece of code generates the list widget in the picture.
QListWidgetItem *it;
it = new QListWidgetItem(ui->listWidget);
ui->listWidget->setItemWidget(it, new QRadioButton(tr("Item 1")));
it = new QListWidgetItem(ui->listWidget);
ui->listWidget->setItemWidget(it, new QRadioButton(tr("Item 2")));
// .
// .
// .
it = new QListWidgetItem(ui->listWidget);
ui->listWidget->setItemWidget(it, new QRadioButton(tr("Item N")));
where ui->listWidget
is a pointer to the QListWidget
that holds the items.
I hope this helps. As far as I understand, that's what you need.