29 setMinimumSize( QSize( 100, 40 ) );
34 setMinimumSize( QSize( 100, 40 ) );
39 QSlider::paintEvent( event );
40 QPainter painter(
this );
41 const QRect rect = geometry();
42 painter.setPen( QPen( palette().color( QPalette::WindowText ) ) );
43 painter.drawText( QRectF( 0, rect.height() * 0.5, rect.width(), rect.height() ),
72void QgsSlider::update()
80 if ( mMin.type() == QVariant::Int &&
81 mMax.type() == QVariant::Int &&
82 mStep.type() == QVariant::Int &&
83 mValue.type() == QVariant::Int )
85 QSlider::setMinimum( mMin.toInt() );
86 QSlider::setMaximum( mMax.toInt() );
87 QSlider::setSingleStep( mStep.toInt() );
88 QSlider::setValue( mValue.toInt() );
93 QSlider::setMinimum( 0 );
95 const int max = std::ceil( ( mMax.toDouble() - mMin.toDouble() ) / mStep.toDouble() );
96 if ( maximum() != max )
97 QSlider::setMaximum( max );
99 if ( singleStep() != 1 )
100 QSlider::setSingleStep( 1 );
102 QSlider::setValue( std::ceil( ( mValue.toDouble() - mMin.toDouble() ) / mStep.toDouble() ) );
105 connect(
this, &QSlider::valueChanged,
this, &QgsSlider::onValueChanged );
113void QgsSlider::onValueChanged(
int value )
119 else if ( mMin.type() == QVariant::Int &&
120 mMax.type() == QVariant::Int &&
121 mStep.type() == QVariant::Int &&
122 mValue.type() == QVariant::Int )
128 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)
Returns true if the specified variant should be considered a NULL value.