1

When I change the standard slider standard slider with setStyleSheet:

mySlider = new QSlider(Qt::Horizontal, this);

mySlider->setStyleSheet("QSlider::handle:horizontal { border: 1px solid #777; background:#92B558;}");

The resulting slider looks like this:changed slider

What I want is to keep the shape of the standard slider with a different colour. Is there another way to recolour the standard slider, or to create another handle which looks similar?

JustWe
  • 4,250
  • 3
  • 39
  • 90
Gpipe
  • 13
  • 3
  • 1
    For me (Windows 10) the handle has the same rectangular shape with and without setting a style sheet. Where do you see the difference? – vahancho Apr 10 '18 at 08:55
  • As far as I know thats not really possible with stylesheets. If it is possible, then only by overrriding the draw methods and draw the handle yourself – Felix Apr 10 '18 at 11:38
  • @vahancho sry for not clarifying the shape with a tip appears if you use myslider->setTickPosition(QSlider::TicksBelow); – Gpipe Apr 11 '18 at 08:31

1 Answers1

1

I'm afraid that is not possible, since the shape of the slider is actually painted using the application QStyle. When assigning a style sheet rule for the slider, that rule will override the painting done by QStyle. Have a look at the implementation of QFusionStyle for more details.

To achieve your goal you can prepare a pixmap with the exact shape and color of the slider and then specify it as the background in your stylesheet code.

Otherwise, you may subclass and do all the paining by yourself in the paintEvent, but I think it's an overkill if you only want to change the color of the slider IMHO.

Sergio Monteleone
  • 2,776
  • 9
  • 21