Add QCheckBox in every cells of a column in QTable Widget
Solved
General and Desktop
-
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.
-
@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); }