Unsolved SpinBoxDelegate example.
-
Hi,
I was reviewing the following SpinBoxDelegate example code:
https://doc.qt.io/qt-5/qtwidgets-itemviews-spinboxdelegate-example.htmlWanted 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);
editor->setFrame(false);
editor->setMinimum(0);
editor->setMaximum(100);
editor->setAlignment(Qt::AlignHCenter);return editor;
}
and...
void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QSpinBox spinBox = static_cast<QSpinBox>(editor);
spinBox->interpretText();
int value = spinBox->value();model->setData(index, value, Qt::EditRole); **model->setData(index, Qt::AlignHCenter, Qt::TextAlignmentRole);**
}
Thanks.
-
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.
-
@leeroy
Hi
It has align.