samedi 10 juin 2023

How to align checkboxes created using roles to the center of the cell in QTableWidget?

In my Qt C++ Windows application, I create checkboxes in my table using roles:

QTableWidgetItem* item = new QTableWidgetItem();
item->setData(Qt::CheckStateRole, QVariant::fromValue(dev.is_active ? Qt::Checked : Qt::Unchecked));
ui.tableWidget->setItem(i, ui_columns_positions.at(table_columns::IsActive), item);

The problem is that checkboxes are left-aligned. I need to align them to the center of the cell. left-aligned checkboxes

I've already tried various alignment methods, but none of them work. For example, I created a style for alignment, I made a delegate class - nothing worked. How to align checkboxes created using roles to the center of the cell in QTableWidget?




Aucun commentaire:

Enregistrer un commentaire