c++qtqt5qtstylesheetsqslider

QSlider handle is being hidden when changing the background of the groove


I'm trying to change the background image of the groove, and set an image on the handle.

While doing so, I ran into a situation where the handle (which works) is being covered by the groove the moment that I set the background to anything.

This simple example shows the issue when I change just the color and nothing else. The groove covers the handle with this bit of code. (user cannot slide now) I'm missing something critical. What am I missing?

mySlider = new QSlider(centralWidget);
mySlider->setObjectName(QStringLiteral("mySlider"));
mySlider->setGeometry(QRect(960, 500, 100, 25));
mySlider->setOrientation(Qt::Horizontal);
mySlider->setStyleSheet("QSlider::groove:horizontal {background-color:yellow;}");

Here's what the slider looks like:

enter image description here


Solution

  • It seems to be a bug, it seems that the handle is resized to a size that makes it invisible, but if it can move with some difficulty. The last statement I checked with the following code.

     connect(mySlider, &QSlider::valueChanged, [=](int value){
         qDebug()<<value;
     });
    

    It is advisable to place a width and height, by example:

    mySlider->setStyleSheet("QSlider::groove:horizontal {background-color:yellow;}"
                            "QSlider::handle:horizontal {background-color:blue; height:16px; width: 16px;}");
    

    enter image description here