Center aligns content of cells in QTableView
1 answer
If you don't want to use custom delegates, you can set this in data
your model's implementation function using Qt::TextAlignmentRole
:
QVariant MyModel::data ( const QModelIndex & index, int role = Qt::DisplayRole )
{
if (role == Qt::TextAlignmentRole )
return Qt::AlignCenter;
else
return QAbstractItemModel::data(index, role);
}
+7
source to share