19 #include <QHBoxLayout>
25 QHBoxLayout *layout =
new QHBoxLayout();
26 layout->setContentsMargins( 0, 0, 0, 0 );
27 layout->setSpacing( 3 );
30 mSlider =
new QSlider();
31 mSlider->setMinimum( 0 );
32 mSlider->setMaximum( 1000 );
33 mSlider->setSingleStep( 10 );
34 mSlider->setPageStep( 100 );
35 mSlider->setValue( 1000 );
36 mSlider->setOrientation( Qt::Horizontal );
37 layout->addWidget( mSlider, 1 );
40 mSpinBox->setMinimum( 0.0 );
41 mSpinBox->setMaximum( 100.0 );
42 mSpinBox->setValue( 100.0 );
44 mSpinBox->setMinimumSize( QSize( 100, 0 ) );
45 mSpinBox->setDecimals( 1 );
46 mSpinBox->setSuffix( tr(
" %" ) );
47 layout->addWidget( mSpinBox, 0 );
49 setFocusProxy( mSpinBox );
51 connect( mSlider, &QSlider::valueChanged,
this, [ = ](
int value ) { mSpinBox->setValue( value / 10.0 ); } );
52 connect( mSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, [ = ](
double value ) {
whileBlocking( mSlider )->setValue( value * 10 ); } );
53 connect( mSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsOpacityWidget::spinChanged );
58 return mSpinBox->value() / 100.0;
63 mSpinBox->setValue(
opacity * 100.0 );
66 void QgsOpacityWidget::spinChanged(
double value )
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
void setClearValue(double customValue, const QString &clearValueText=QString())
Defines the clear value as a custom value and will automatically set the clear value mode to CustomVa...
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.