So far the only solution I have found is to subclass QItemDelegate and implement my alignment rule in the paint() function. Is it really the simplest way?
I am using
Following works for me:
http://doc.qt.io/qt-5/qstandarditem.html#setTextAlignment
void MainWindow::fillTable()
{
sudukoItem->setText( "qq" );
sudukoItem->setTextAlignment(Qt::AlignCenter);
sudukoModel->appendRow( sudukoItem );
sudukoTable->setModel( sudukoModel );
sudukoTable->setRowHeight( ( sudukoModel->rowCount() - 1 ), 100 );
sudukoTable->setColumnWidth( ( sudukoModel->columnCount() - 1 ), 100 );
}
where:
QTableView* sudukoTable;
QStandardItemModel* sudukoModel;
QModelIndex* modelIndex;
QStandardItem* sudukoItem;
Credit goes to this comment: How to set text alignment on a column of QTableView programmatically?
`item->setTextAlignment(Qt::AlignCenter); work well for me. – Ratah