0

Whenever I set the groove of my QSlider to an image (as an image or background-image) or background-color (but not color) I am unable to drag it, but only move it by clicking on the slider to step it. Here is my current stylesheet for reference, this is being set via a call to setStyleSheet()

    fanSliderOnStyleSheet = "QSlider {padding-left: 80px; padding-right: 80px;} \n"
    "QSlider::handle:horizontal{image: url(:/images/FanSlider/blowerSw2.png); padding:-65px; }\n"
    "QSlider::groove:horizontal{background-image: url(:/images/FanSlider/barind.png);}\n";

If i comment out the line that sets the groove the slider works as intended so I've eliminated any other variables of the slider I can think of.

Note: I prefer setting it as a background-image over image as it maintains the true size if I do it this way.

Does anyone have any idea on how to fix this, or is it by chance a bug with Qt? I've been banging my head against the wall on this for the past couple days and my searches haven't revealed any useful information.

1 Answers1

0

The padding is too high for your handle: if you set a value higher than the size of the image in the groove property, it will interfere with the handler movements (the grab section would be empty).

I get exactly the same problem when I set an image with a width to 100px and a padding property to 110px.

Remove the padding and it should be OK:

fanSliderOnStyleSheet = "QSlider {padding-left: 80px; padding-right: 80px;} \n"
    "QSlider::handle:horizontal{image: url(:/images/FanSlider/blowerSw2.png);}\n"
    "QSlider::groove:horizontal{background-image: url(:/images/FanSlider/barind.png);}\n";
Dimitry Ernot
  • 6,256
  • 2
  • 25
  • 37
  • If i remove the padding on my handle the image isn't really visible, it will cut off most of it. Also if I leave the padding and remove the QSlider::groove stylesheet I am able to drag the slider, but the area to grab it is a bit small, I was planning on working on that after I got it working properly with a groove set. – Jacob Bernard Mar 13 '19 at 19:13