Reputation: 13
When I change the 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:
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?
Upvotes: 1
Views: 586
Reputation: 2886
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.
Upvotes: 1