Add QCheckBox in every cells of a column in QTable Widget
-
wrote on 9 Sept 2022, 14:08 last edited by aim0d 9 Sept 2022, 14:08
Hi!
I'm new to QT and I'm trying to create a table using QTableWidget and I would like to insert QCheckboxes in the first column, like this:This is the code I use (for every cells) in this example:
QHBoxLayout *j = new QHBoxLayout(); z->addWidget((new QCheckBox(""))); QWidget *q = new QWidget(); z->setLayout(j); ui->tableWidget->setCellWidget(0,0, z);
Is there a way to do it more automatically, without repeat the code 10times?
Thanks! -
Hi!
I'm new to QT and I'm trying to create a table using QTableWidget and I would like to insert QCheckboxes in the first column, like this:This is the code I use (for every cells) in this example:
QHBoxLayout *j = new QHBoxLayout(); z->addWidget((new QCheckBox(""))); QWidget *q = new QWidget(); z->setLayout(j); ui->tableWidget->setCellWidget(0,0, z);
Is there a way to do it more automatically, without repeat the code 10times?
Thanks!@aim0d said in Add QCheckBox in every cells of a column in QTable Widget:
Is there a way to do it more automatically, without repeat the code 10times?
Put your logic in a loop for every row.
-
@aim0d said in Add QCheckBox in every cells of a column in QTable Widget:
Is there a way to do it more automatically, without repeat the code 10times?
Put your logic in a loop for every row.
wrote on 9 Sept 2022, 14:19 last edited by@Christian-Ehrlicher Oh, so stupid of mine for not thinking about it ahha
thanks!RESULT for future noobie like me:
for(int row=0;row<=12;row++){ QHBoxLayout *a = new QHBoxLayout(); a->addWidget((new QCheckBox(""))); QWidget *z = new QWidget(); z->setLayout(a); ui->tableWidget->setCellWidget(row,0, z); }
2/3