#include "slidergroup.h" SliderGroup::SliderGroup(int min, int max, int decimals, QWidget *parent) : QWidget(parent) { QVBoxLayout *layout = new QVBoxLayout; layout->setAlignment(Qt::AlignHCenter); this->setMaximumWidth(65); slider = new QSlider(Qt::Orientation::Vertical); slider->setFocusPolicy(Qt::StrongFocus); slider->setTickPosition(QSlider::TicksBothSides); slider->setTickInterval((max - min) / 11); slider->setSingleStep(1); slider->setRange(min, max); slider->setMaximumWidth(65); valueBox = new QDoubleSpinBox(); valueBox->setFocusPolicy(Qt::NoFocus); valueBox->setButtonSymbols(QAbstractSpinBox::NoButtons); valueBox->setMaximumWidth(65); valueBox->setRange(min, max); valueBox->setDecimals(decimals); connect(slider, SIGNAL(valueChanged(int)), this, SLOT(sliderValueChanged(int))); layout->addWidget(slider); layout->addWidget(valueBox); this->setLayout(layout); } void SliderGroup::sliderValueChanged(int value) { valueBox->setValue(value); if (valueBox->decimals() > 1) value /= 100.0f; emit valueChanged(value); }; void SliderGroup::setValue(float value) { slider->setValue(value); valueBox->setValue(value); }