Search code examples
qt4qtablewidgetqt4.7

Align cell widget in center within QTableWidget?


How can I align my table widget items in center ? My first column was a QCheckBox , but I checked documents , seems you can only set alignment for QTableWidgetItem , not the cell widget inside.

Thanks


Solution

  • Setting model to your TableWidget (with data virtual implementation) I think will help. QVariant QAbstractItemModel::data ( const QModelIndex & index, int role = Qt::DisplayRole ) const [pure virtual] and return the needed alignment if role is an alignment.