Resizable Slider widget aka Range Indicator
-
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):!http://s2.picofile.com/file/7911319886/s6.png(s)!
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:
- When orientation is horizontal, widget looks weird:
!http://s3.picofile.com/file/7911329137/s66.png(Vertical)!
!http://s1.picofile.com/file/7911327197/s7.png(Horizontal)! - I don't know how to add scroll handle
Any help to drawing widget and/or adding functionality is appropriate
- When orientation is horizontal, widget looks weird: