inverse the alignment of the line editor of QAbstractSpinBox

because that is how I want it to be

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-05-22 10:12:44 +03:00
parent 9ead9c9837
commit 79236242c8

View file

@ -408,7 +408,6 @@ QAbstractSpinBox::CorrectionMode QAbstractSpinBox::correctionMode() const
return d->correctionMode; return d->correctionMode;
} }
/*! /*!
\property QAbstractSpinBox::acceptableInput \property QAbstractSpinBox::acceptableInput
\brief whether the input satisfies the current validation \brief whether the input satisfies the current validation
@ -440,14 +439,12 @@ bool QAbstractSpinBox::hasAcceptableInput() const
Qt::Alignment QAbstractSpinBox::alignment() const Qt::Alignment QAbstractSpinBox::alignment() const
{ {
Q_D(const QAbstractSpinBox); Q_D(const QAbstractSpinBox);
return d->edit->alignment();
return (Qt::Alignment)d->edit->alignment();
} }
void QAbstractSpinBox::setAlignment(Qt::Alignment flag) void QAbstractSpinBox::setAlignment(Qt::Alignment flag)
{ {
Q_D(QAbstractSpinBox); Q_D(QAbstractSpinBox);
d->edit->setAlignment(flag); d->edit->setAlignment(flag);
} }
@ -601,7 +598,7 @@ void QAbstractSpinBox::stepBy(int steps)
This function returns a pointer to the line edit of the spin box. This function returns a pointer to the line edit of the spin box.
*/ */
QLineEdit *QAbstractSpinBox::lineEdit() const QLineEdit* QAbstractSpinBox::lineEdit() const
{ {
Q_D(const QAbstractSpinBox); Q_D(const QAbstractSpinBox);
@ -1442,7 +1439,15 @@ void QAbstractSpinBoxPrivate::init()
{ {
Q_Q(QAbstractSpinBox); Q_Q(QAbstractSpinBox);
q->setLineEdit(new QLineEdit(q)); QLineEdit* lineedit = new QLineEdit(q);
// inverse alignment of QLineEdit to put the text next to the arrows and expand text in the
// other direction
if (q->layoutDirection() == Qt::RightToLeft) {
lineedit->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
} else {
lineedit->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
}
q->setLineEdit(lineedit);
edit->setObjectName(QLatin1String("qt_spinbox_lineedit")); edit->setObjectName(QLatin1String("qt_spinbox_lineedit"));
validator = new QSpinBoxValidator(q, this); validator = new QSpinBoxValidator(q, this);
edit->setValidator(validator); edit->setValidator(validator);