Change the color of a QProgressBar

后端 未结 3 1625
情书的邮戳
情书的邮戳 2021-02-07 10:38

I am running ubuntu 11.04. This is what my progress bars look like:

\"progress

I am showing the progr

3条回答
  •  你的背包
    2021-02-07 11:21

    I had this problem too, but I find a way, with the help of this site: http://thesmithfam.org/blog/2009/10/13/cool-qprogressbar-stylesheet/

    but I just wanted to change the color and not the progressbar itself. so I got rid of the first line, and change the second one a little bit.

    Finally I got what I wanted.

    First do this:

    QString danger = "QProgressBar::chunk {background: QLinearGradient( x1: 0, y1: 0, x2: 1, y2: 0,stop: 0 #FF0350,stop: 0.4999 #FF0020,stop: 0.5 #FF0019,stop: 1 #FF0000 );border-bottom-right-radius: 5px;border-bottom-left-radius: 5px;border: .px solid black;}";
    QString safe= "QProgressBar::chunk {background: QLinearGradient( x1: 0, y1: 0, x2: 1, y2: 0,stop: 0 #78d,stop: 0.4999 #46a,stop: 0.5 #45a,stop: 1 #238 );border-bottom-right-radius: 7px;border-bottom-left-radius: 7px;border: 1px solid black;}";
    

    Now all you have to do is:

    if(ui->progressbar->value()<80)
        ui->progressbar->setStyleSheet(danger);
    else
        ui->progressbar->setStyleSheet(safe);
    

提交回复
热议问题