Unsolved QSlider in Windows Volume Mixer Style
-
Hi guys,
Does someone have a cool solution to creating a Windows Volume Mixer Style QSlider?
It would be nice if it's something I can simply copy into the QtCreator stylesheet field.
Thanks in Advance,
MegamouseEdit: It doesn't have to be exactly the same. Just the triangular background would be enough already
-
@Megamouse
you just need to subclassQSlider
, and override itspaintEvent()
and draw the triangle-like shape within it. -
@Megamouse
I don't think that with stylesheets only this is achievable on QSlider (directly).I really don't know how it will look like, but generally you can do something like this:
void MySlider::paintEvent(QPaintEvent *) { QPainter p(this); QStyleOptionSlider opt; initStyleOption(&opt); // draw rectangle QPainterPath path; path.moveTo( opt.rect.bottomLeft() ); path.lineTo( opt.rect.topRight() ); path.lineTo( opt.rect.topLeft() ); path.lineTo( opt.rect.bottomLeft() ); path.closeSubpath(); p.saveState(); p.setPen( Qt::NoPen ); p.setBrush( QBrush(Qt::lightGray) ); p.drawPath(path); p.restoreState(); // draw slider opt.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle; if (d->tickPosition != NoTicks) opt.subControls |= QStyle::SC_SliderTickmarks; if ( isSliderDown() ) { opt.activeSubControls = isSliderDown(); opt.state |= QStyle::State_Sunken; } else { opt.activeSubControls = d->hoverControl; } style()->drawComplexControl(QStyle::CC_Slider, &opt, &p, this); }
Maybe the triangle coordinates need some more adjustments.