21 #include <QPaintEvent>
28 setMinimumSize( QSize( 100, 40 ) );
33 setMinimumSize( QSize( 100, 40 ) );
38 QSlider::paintEvent( event );
39 QPainter painter(
this );
40 const QRect rect = geometry();
41 painter.setPen( QPen( palette().color( QPalette::WindowText ) ) );
42 painter.drawText( QRectF( 0, rect.height() * 0.5, rect.width(), rect.height() ),
71 void QgsSlider::update()
73 if ( mMin.isNull() || mMax.isNull() || mStep.isNull() )
76 if ( mValue.isNull() )
79 if ( mMin.type() == QVariant::Int &&
80 mMax.type() == QVariant::Int &&
81 mStep.type() == QVariant::Int &&
82 mValue.type() == QVariant::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 );
112 void QgsSlider::onValueChanged(
int value )
114 if ( mMin.isNull() || mMax.isNull() || mStep.isNull() )
118 else if ( mMin.type() == QVariant::Int &&
119 mMax.type() == QVariant::Int &&
120 mStep.type() == QVariant::Int &&
121 mValue.type() == QVariant::Int )
127 mValue = QVariant( mMin.toDouble() + value * mStep.toDouble() );