Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Changing the color of the handle of a vertical QSlider looses the shape and the other states



  • This is the normal behavior of the handle of the slider

    Normal:
    normal.png
    Hover:
    hover.png
    Disable:
    disable_or_pressed.png !

    I want this but change the blue color for rgb(72, 66, 66) .

    I tried to change the blue color like this

    QSlider::handle:vertical {
    	height: 4px;
    	background-color: rgb(72, 66, 66);
     	margin: 0 -4px; /* expand outside the groove */
    	border-radius: 8px;
    	width: 8px;
    }
    

    But it looses the shape and looses the hover and disable state. It always looks like this

    result_of_changing_color.png

    How can I change the color without loosing the shape and the other states?


  • Lifetime Qt Champion

    Hi
    Stylesheets are all or nothing.
    As soon as you apply a stylesheet to a widget, the normal drawing is
    no longer in effect/changes.

    So you have to style all of it. including the shape to look like it used to
    and hover effects.

    QSlider::handle:vertical:hover {
    background-color: rgb(...);
    }

    So thats one of the downsides with stylesheets.


Log in to reply