Important: Please read the Qt Code of Conduct -

How to change QProgressBar color

  • Hi,
    I would like to change color of my progress bar from default green to red. I have this code, but the view is "flat", I would like to achieve something like "3d effect" as on picture below:

    Code for red PB:
    QPalette pal = ui->pbExtractionWidget->palette();
    pal.setColor(QPalette::Normal, QColor(Qt::red));
    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;}";
    This is how it looks:

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    It's the style sheet that triggers that as the widget is rendered through a different style and doesn't follow the system style anymore.

Log in to reply