Important: Please read the Qt Code of Conduct -

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,

    Edit: It doesn't have to be exactly the same. Just the triangular background would be enough already

  • @Megamouse
    you just need to subclass QSlider, and override its paintEvent() and draw the triangle-like shape within it.

  • Moderators

    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;
        // draw rectangle
        QPainterPath path;
           path.moveTo( opt.rect.bottomLeft() );
           path.lineTo( opt.rect.topRight() );
           path.lineTo( opt.rect.topLeft() );
           path.lineTo( opt.rect.bottomLeft() );
          p.setPen( Qt::NoPen );
          p.setBrush( QBrush(Qt::lightGray) );
        // 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.

Log in to reply