Skip to content

Commit bbf6214

Browse files
committed
Add method to set line edit alignment in Qgs(Double)SpinBox
1 parent 287f822 commit bbf6214

File tree

7 files changed

+38
-2
lines changed

7 files changed

+38
-2
lines changed

python/gui/editorwidgets/qgsdoublespinbox.sip.in

+7
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ Defines if the clear value should be the minimum or maximum values of the widget
117117
Returns the value used when clear() is called.
118118

119119
.. seealso:: :py:func:`setClearValue`
120+
%End
121+
122+
void setLineEditAlignment( Qt::Alignment alignment );
123+
%Docstring
124+
Set alignment in the embedded line edit widget
125+
126+
:param alignment:
120127
%End
121128

122129
virtual double valueFromText( const QString &text ) const;

python/gui/editorwidgets/qgsspinbox.sip.in

+7
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ Defines if the clear value should be the minimum or maximum values of the widget
117117
Returns the value used when clear() is called.
118118

119119
.. seealso:: :py:func:`setClearValue`
120+
%End
121+
122+
void setLineEditAlignment( Qt::Alignment alignment );
123+
%Docstring
124+
Set alignment in the embedded line edit widget
125+
126+
:param alignment:
120127
%End
121128

122129
virtual int valueFromText( const QString &text ) const;

src/gui/editorwidgets/qgsdoublespinbox.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ QgsDoubleSpinBox::QgsDoubleSpinBox( QWidget *parent )
3434
// By default, group separator is off
3535
setLocale( QLocale( QgsApplication::locale( ) ) );
3636
setLineEdit( mLineEdit );
37-
mLineEdit->setAlignment( Qt::AlignRight );
3837

3938
QSize msz = minimumSizeHint();
4039
setMinimumSize( msz.width() + CLEAR_ICON_SIZE + 9 + frameWidth() * 2 + 2,
@@ -137,6 +136,11 @@ double QgsDoubleSpinBox::clearValue() const
137136
return mCustomClearValue;
138137
}
139138

139+
void QgsDoubleSpinBox::setLineEditAlignment( Qt::Alignment alignment )
140+
{
141+
mLineEdit->setAlignment( alignment );
142+
}
143+
140144
QString QgsDoubleSpinBox::stripped( const QString &originalText ) const
141145
{
142146
//adapted from QAbstractSpinBoxPrivate::stripped

src/gui/editorwidgets/qgsdoublespinbox.h

+6
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
126126
*/
127127
double clearValue() const;
128128

129+
/**
130+
* Set alignment in the embedded line edit widget
131+
* \param alignment
132+
*/
133+
void setLineEditAlignment( Qt::Alignment alignment );
134+
129135
double valueFromText( const QString &text ) const override;
130136
QValidator::State validate( QString &input, int &pos ) const override;
131137
void paintEvent( QPaintEvent *e ) override;

src/gui/editorwidgets/qgsrangewidgetwrapper.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ QWidget *QgsRangeWidgetWrapper::createWidget( QWidget *parent )
4747
case QVariant::Double:
4848
{
4949
editor = new QgsDoubleSpinBox( parent );
50+
static_cast<QgsDoubleSpinBox *>( editor )->setLineEditAlignment( Qt::AlignRight );
5051
break;
5152
}
5253
case QVariant::Int:
5354
case QVariant::LongLong:
5455
default:
5556
editor = new QgsSpinBox( parent );
57+
static_cast<QgsSpinBox *>( editor )->setLineEditAlignment( Qt::AlignRight );
5658
break;
5759
}
5860
}

src/gui/editorwidgets/qgsspinbox.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ QgsSpinBox::QgsSpinBox( QWidget *parent )
3030
: QSpinBox( parent )
3131
{
3232
mLineEdit = new QgsSpinBoxLineEdit();
33-
mLineEdit->setAlignment( Qt::AlignRight );
3433
setLineEdit( mLineEdit );
3534

3635
QSize msz = minimumSizeHint();
@@ -133,6 +132,11 @@ int QgsSpinBox::clearValue() const
133132
return mCustomClearValue;
134133
}
135134

135+
void QgsSpinBox::setLineEditAlignment( Qt::Alignment alignment )
136+
{
137+
mLineEdit->setAlignment( alignment );
138+
}
139+
136140
int QgsSpinBox::valueFromText( const QString &text ) const
137141
{
138142
if ( !mExpressionsEnabled )

src/gui/editorwidgets/qgsspinbox.h

+6
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ class GUI_EXPORT QgsSpinBox : public QSpinBox
126126
*/
127127
int clearValue() const;
128128

129+
/**
130+
* Set alignment in the embedded line edit widget
131+
* \param alignment
132+
*/
133+
void setLineEditAlignment( Qt::Alignment alignment );
134+
129135
int valueFromText( const QString &text ) const override;
130136
QValidator::State validate( QString &input, int &pos ) const override;
131137

0 commit comments

Comments
 (0)