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.userType() == QMetaType::Type::Int &&
81 mMax.userType() == QMetaType::Type::Int &&
82 mStep.userType() == QMetaType::Type::Int &&
83 mValue.userType() == QMetaType::Type::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.userType() == QMetaType::Type::Int &&
120 mMax.userType() == QMetaType::Type::Int &&
121 mStep.userType() == QMetaType::Type::Int &&
122 mValue.userType() == QMetaType::Type::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, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.