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

This commit is contained in:
Alessandro Pasotti 2018-02-02 08:12:12 +01:00
parent 287f82286b
commit bbf621411a
7 changed files with 38 additions and 2 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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 )

View File

@ -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;