I would like to create a window in Qt that contains a QTableWidget
composed of 4 columns, one of text and the last 3 are QRadioButtons
.
I was able to create this:
However, I am unable to group the QRadioButton
s by row. Indeed, with this current UI, I can only select ONE radio from the 30 displayed, instead of one per row.
Here's my code:
// 1st col stretchable, other 3 fixed width
QHeaderView *header = ui->tableWidget->horizontalHeader();
header->setResizeMode(QHeaderView::Stretch);
header->setResizeMode(1, QHeaderView::Interactive);
header->setResizeMode(2, QHeaderView::Interactive);
header->setResizeMode(3, QHeaderView::Interactive);
// Can't select lines
ui->tableWidget->setSelectionMode(QAbstractItemView::NoSelection);
// Test: fill the list
ui->tableWidget->setRowCount(10);
QLabel *nom;
QRadioButton *radio1, *radio2, *radio3;
for (int i = 0; i < 10; i++) {
nom = new QLabel();
nom->setText(QString("test")+QString::number(i));
ui->tableWidget->setCellWidget(i, 0, nom);
radio1 = new QRadioButton();
radio2 = new QRadioButton();
radio3 = new QRadioButton();
ui->tableWidget->setCellWidget(i, 1, radio1);
ui->tableWidget->setCellWidget(i, 2, radio2);
ui->tableWidget->setCellWidget(i, 3, radio3);
}
How can I do this?