Qt - Centering a checkbox in a QTable

Mitch picture Mitch · Feb 13, 2013 · Viewed 15.5k times · Source

In QtCreater I added a table to my project. in my code I am generating some data to output into the table. I want to add a QCheckbox into each row to allow the row to be selected. All the content of the table is aligned left, how do I make only these checkboxes in the first column of every row align to the center?

I'm adding the QCheckbox using:

ui->data_table->setCellWidget(rowCount,0, new QCheckBox);

Answer

Ph0t0n picture Ph0t0n · Oct 21, 2014

Two thumbs up for Barry Mavin! You don't even have to subclass.

one line...

pCheckBox->setStyleSheet("margin-left:50%; margin-right:50%;");

done!!