2#include <QtWidgets/QStyleOptionSlider>
5 : QSlider(orientation, parent), m_lowerValue(0), m_upperValue(maximum()) {}
15void DoubleSlider::setLowerValue(
int value) {
16 if (value < minimum()) value = minimum();
17 if (value > m_upperValue) value = m_upperValue;
22void DoubleSlider::setUpperValue(
int value) {
23 if (value > maximum()) value = maximum();
24 if (value < m_lowerValue) value = m_lowerValue;
30 QSlider::paintEvent(event);
31 QPainter painter(
this);
33 QStyleOptionSlider opt;
34 initStyleOption(&opt);
36 QRect groove = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove,
this);
37 QRect handleLower = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle,
this);
38 QRect handleUpper = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle,
this);
40 handleLower.moveLeft(lowerValueToPos());
41 handleUpper.moveLeft(upperValueToPos());
43 painter.fillRect(groove, Qt::gray);
44 painter.fillRect(handleLower, Qt::blue);
45 painter.fillRect(handleUpper, Qt::blue);
48int DoubleSlider::lowerValueToPos()
const {
49 return static_cast<int>((m_lowerValue - minimum()) /
static_cast<double>(maximum() - minimum()) * width());
52int DoubleSlider::upperValueToPos()
const {
53 return static_cast<int>((m_upperValue - minimum()) /
static_cast<double>(maximum() - minimum()) * width());
DoubleSlider(Qt::Orientation orientation, QWidget *parent=nullptr)
コンストラクタ
void paintEvent(QPaintEvent *event) override
ペイントイベント。2つのハンドルをスロット上に描画する