I want a widget to specify a date range. It should look like a slider with two handles.
I know there is QxtSpanSlider but it does not fit in my requirements. What I need is a slider with two handles and a scroll handle between them. Area between two handles should be colored. Scroll handle should take a constant percent of space (say 60%) unless handles are too close . In that case, scroll handle should not be shown.
The widget looks like this (on Ubuntu / KDE / Oxygen theme) (GIMPed of course):
What I’ve tried so far is a class derived from QSlider that re-implements paintEvent:
void ScrollScaler::paintEvent(QPaintEvent *e)
{
QStylePainter painter(this);
QStyleOptionSlider opt;
QStyleOptionSlider opt2;
initStyleOption(&opt);
initStyleOption(&opt2);
opt.initFrom(this);
opt2.initFrom(this);
//opt.dialWrapping = false;
opt.sliderValue = 50;
opt.sliderPosition = 50;
opt.orientation = Qt::Vertical;
opt.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderTickmarks ;
opt2.sliderPosition = 20;
opt2.subControls = QStyle::SC_SliderHandle;
// opt.rect = this->rect();
painter.drawComplexControl(QStyle::CC_Slider, opt);
painter.drawComplexControl(QStyle::CC_Slider, opt2);
opt2.sliderPosition = 80;
painter.drawComplexControl(QStyle::CC_Slider, opt2);
// Trying to draw scroll handle:
QStyleOptionComplex soc;
soc.subControls = QStyle::SC_ScrollBarSlider;
soc.initFrom(this);
painter.drawComplexControl(QStyle::CC_ScrollBar, soc);
e->accept();
}
I have a couple of problems:
1. When orientation is horizontal, widget looks weird:
2. I don’t know how to add scroll handle
Any help to drawing widget and/or adding functionality is appropriate
↧