Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
I was reviewing the following SpinBoxDelegate example code:
Wanted to know if there is a way to centre align the value on the spinbox's? I tried a few variations including the following but neither is working.
QWidget *SpinBoxDelegate::createEditor(QWidget parent,
const QStyleOptionViewItem &/ option /,
const QModelIndex &/ index */) const
QSpinBox *editor = new QSpinBox(parent);
void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
QSpinBox spinBox = static_cast<QSpinBox>(editor);
int value = spinBox->value();
model->setData(index, value, Qt::EditRole); **model->setData(index, Qt::AlignHCenter, Qt::TextAlignmentRole);**
Hi and welcome to devnet,
Do you want to center the content of the cell or the content of the spin box ?
Hi @SGaist I would like to centre the content of the spinbox.
Hi @SGaist any thoughts how the content of the spinbox can be centred? Thanks in advance.
It has align.