19#include "moc_qgsslider.cpp"
30 setMinimumSize( QSize( 100, 40 ) );
35 setMinimumSize( QSize( 100, 40 ) );
40 QSlider::paintEvent( event );
41 QPainter painter(
this );
42 const QRect rect = geometry();
43 painter.setPen( QPen( palette().color( QPalette::WindowText ) ) );
44 painter.drawText( QRectF( 0, rect.height() * 0.5, rect.width(), rect.height() ),
73void QgsSlider::update()
81 if ( mMin.userType() == QMetaType::Type::Int &&
82 mMax.userType() == QMetaType::Type::Int &&
83 mStep.userType() == QMetaType::Type::Int &&
84 mValue.userType() == QMetaType::Type::Int )
86 QSlider::setMinimum( mMin.toInt() );
87 QSlider::setMaximum( mMax.toInt() );
88 QSlider::setSingleStep( mStep.toInt() );
89 QSlider::setValue( mValue.toInt() );
94 QSlider::setMinimum( 0 );
96 const int max = std::ceil( ( mMax.toDouble() - mMin.toDouble() ) / mStep.toDouble() );
97 if ( maximum() != max )
98 QSlider::setMaximum( max );
100 if ( singleStep() != 1 )
101 QSlider::setSingleStep( 1 );
103 QSlider::setValue( std::ceil( ( mValue.toDouble() - mMin.toDouble() ) / mStep.toDouble() ) );
106 connect(
this, &QSlider::valueChanged,
this, &QgsSlider::onValueChanged );
114void QgsSlider::onValueChanged(
int value )
120 else if ( mMin.userType() == QMetaType::Type::Int &&
121 mMax.userType() == QMetaType::Type::Int &&
122 mStep.userType() == QMetaType::Type::Int &&
123 mValue.userType() == QMetaType::Type::Int )
129 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.