Qt World Summit: Submit your Presentation

CSS, QSlider, set background, handle not visible anymore

  • Hi,

    i have the following code:
    @CustomSlider::CustomSlider(QWidget *parent) :
    QObject::connect(this, SIGNAL(sliderMoved(int)), this, SLOT(valueChanged(int)));

    void CustomSlider::valueChanged(int value)
    int c = (int)(2.55*value);
    QString stylesheet = "QSlider::groove:horizontal { background: rgba(" + QString::number(c) + ", 0, 0, " + QString::number(c) + ");}";

    I want the slider to change the background color depending on the current value of the slider. The higher the value, the more red i want the background to be. The color changing effect works, except the handle is not visible anymore. This makes no sense to me, because i really just set the background of the slider, which should not effect the handle or the visibility of the handle.
    I think i miss something essential but i can't figure out what. I have no idea why setting the background color of a slider changes the handle to not visible.
    Can someone give me some hints why this is happening and how i can avoid it? Thanks in advance!

  • when you modify your css for a widget consisting of multiple elements you must define css for every item otherwise the other items will be set to default (sometimes hidden)

Log in to reply