19#include "moc_qgsslider.cpp"
31 setMinimumSize( QSize( 100, 40 ) );
35 : QSlider( orientation, parent )
37 setMinimumSize( QSize( 100, 40 ) );
42 QSlider::paintEvent( event );
43 QPainter painter(
this );
44 const QRect rect = geometry();
45 painter.setPen( QPen( palette().color( QPalette::WindowText ) ) );
46 painter.drawText( QRectF( 0, rect.height() * 0.5, rect.width(), rect.height() ), Qt::AlignHCenter,
variantValue().toString(),
nullptr );
74void QgsSlider::update()
82 if ( mMin.userType() == QMetaType::Type::Int && mMax.userType() == QMetaType::Type::Int && mStep.userType() == QMetaType::Type::Int && mValue.userType() == QMetaType::Type::Int )
84 QSlider::setMinimum( mMin.toInt() );
85 QSlider::setMaximum( mMax.toInt() );
86 QSlider::setSingleStep( mStep.toInt() );
87 QSlider::setValue( mValue.toInt() );
92 QSlider::setMinimum( 0 );
94 const int max = std::ceil( ( mMax.toDouble() - mMin.toDouble() ) / mStep.toDouble() );
95 if ( maximum() != max )
96 QSlider::setMaximum( max );
98 if ( singleStep() != 1 )
99 QSlider::setSingleStep( 1 );
101 QSlider::setValue( std::ceil( ( mValue.toDouble() - mMin.toDouble() ) / mStep.toDouble() ) );
104 connect(
this, &QSlider::valueChanged,
this, &QgsSlider::onValueChanged );
112void QgsSlider::onValueChanged(
int value )
118 else if ( mMin.userType() == QMetaType::Type::Int && mMax.userType() == QMetaType::Type::Int && mStep.userType() == QMetaType::Type::Int && mValue.userType() == QMetaType::Type::Int )
124 mValue = QVariant( mMin.toDouble() + value * mStep.toDouble() );
void valueChanged(const QVariant &)
void setSingleStep(const QVariant &step)
void setMinimum(const QVariant &min)
QgsSlider(QWidget *parent=nullptr)
Constructor for QgsSlider.
void setValue(const QVariant &value)
void setMaximum(const QVariant &max)
void paintEvent(QPaintEvent *event) override
QVariant variantValue() const
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.