Skip to content
Permalink
Browse files

Add method to set line edit alignment in Qgs(Double)SpinBox

  • Loading branch information
elpaso committed Feb 2, 2018
1 parent 287f822 commit bbf621411a5615362ac7eef8e27738dba71037f7
@@ -117,6 +117,13 @@ Defines if the clear value should be the minimum or maximum values of the widget
Returns the value used when clear() is called.

.. seealso:: :py:func:`setClearValue`
%End

void setLineEditAlignment( Qt::Alignment alignment );
%Docstring
Set alignment in the embedded line edit widget

:param alignment:
%End

virtual double valueFromText( const QString &text ) const;
@@ -117,6 +117,13 @@ Defines if the clear value should be the minimum or maximum values of the widget
Returns the value used when clear() is called.

.. seealso:: :py:func:`setClearValue`
%End

void setLineEditAlignment( Qt::Alignment alignment );
%Docstring
Set alignment in the embedded line edit widget

:param alignment:
%End

virtual int valueFromText( const QString &text ) const;
@@ -34,7 +34,6 @@ QgsDoubleSpinBox::QgsDoubleSpinBox( QWidget *parent )
// By default, group separator is off
setLocale( QLocale( QgsApplication::locale( ) ) );
setLineEdit( mLineEdit );
mLineEdit->setAlignment( Qt::AlignRight );

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

void QgsDoubleSpinBox::setLineEditAlignment( Qt::Alignment alignment )
{
mLineEdit->setAlignment( alignment );
}

QString QgsDoubleSpinBox::stripped( const QString &originalText ) const
{
//adapted from QAbstractSpinBoxPrivate::stripped
@@ -126,6 +126,12 @@ class GUI_EXPORT QgsDoubleSpinBox : public QDoubleSpinBox
*/
double clearValue() const;

/**
* Set alignment in the embedded line edit widget
* \param alignment
*/
void setLineEditAlignment( Qt::Alignment alignment );

double valueFromText( const QString &text ) const override;
QValidator::State validate( QString &input, int &pos ) const override;
void paintEvent( QPaintEvent *e ) override;
@@ -47,12 +47,14 @@ QWidget *QgsRangeWidgetWrapper::createWidget( QWidget *parent )
case QVariant::Double:
{
editor = new QgsDoubleSpinBox( parent );
static_cast<QgsDoubleSpinBox *>( editor )->setLineEditAlignment( Qt::AlignRight );
break;
}
case QVariant::Int:
case QVariant::LongLong:
default:
editor = new QgsSpinBox( parent );
static_cast<QgsSpinBox *>( editor )->setLineEditAlignment( Qt::AlignRight );
break;
}
}
@@ -30,7 +30,6 @@ QgsSpinBox::QgsSpinBox( QWidget *parent )
: QSpinBox( parent )
{
mLineEdit = new QgsSpinBoxLineEdit();
mLineEdit->setAlignment( Qt::AlignRight );
setLineEdit( mLineEdit );

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

void QgsSpinBox::setLineEditAlignment( Qt::Alignment alignment )
{
mLineEdit->setAlignment( alignment );
}

int QgsSpinBox::valueFromText( const QString &text ) const
{
if ( !mExpressionsEnabled )
@@ -126,6 +126,12 @@ class GUI_EXPORT QgsSpinBox : public QSpinBox
*/
int clearValue() const;

/**
* Set alignment in the embedded line edit widget
* \param alignment
*/
void setLineEditAlignment( Qt::Alignment alignment );

int valueFromText( const QString &text ) const override;
QValidator::State validate( QString &input, int &pos ) const override;

0 comments on commit bbf6214

Please sign in to comment.
You can’t perform that action at this time.