Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSlider in Windows Volume Mixer Style

QSlider in Windows Volume Mixer Style

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 655 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MegamouseM Offline
    MegamouseM Offline
    Megamouse
    wrote on last edited by Megamouse
    #1

    Hi guys,

    Does someone have a cool solution to creating a Windows Volume Mixer Style QSlider?

    0_1540052841895_f62bccc8-f210-4b18-94fb-5929f66158ee-image.png

    It would be nice if it's something I can simply copy into the QtCreator stylesheet field.

    Thanks in Advance,
    Megamouse

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

    U raven-worxR 2 Replies Last reply
    0
    • MegamouseM Megamouse

      Hi guys,

      Does someone have a cool solution to creating a Windows Volume Mixer Style QSlider?

      0_1540052841895_f62bccc8-f210-4b18-94fb-5929f66158ee-image.png

      It would be nice if it's something I can simply copy into the QtCreator stylesheet field.

      Thanks in Advance,
      Megamouse

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

      U Offline
      U Offline
      user4592357
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • MegamouseM Megamouse

        Hi guys,

        Does someone have a cool solution to creating a Windows Volume Mixer Style QSlider?

        0_1540052841895_f62bccc8-f210-4b18-94fb-5929f66158ee-image.png

        It would be nice if it's something I can simply copy into the QtCreator stylesheet field.

        Thanks in Advance,
        Megamouse

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

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        @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.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved