Progressbar with two different colors

  • how to display the progress bar with two different colors(e.g 65% of progress bar with gray color and 35% of progress bar with blue color)


  • I've found an example, try this :)
    QPalette pal = progress->palette();

    // Set the bar red
    pal.setColor(QColorGroup::Highlight, QColor("red"));

    // Set the percentage text yellow
    pal.setColor(QColorGroup::Foreground, QColor("yellow"));

    // Set the background green
    pal.setColor(QColorGroup::Background, QColor("green"));


  • I think what Veeresh is describing is a bar whose color is different at different locations: say, an RPM meter that is green for 90% of the range and red for 10%: to my knowledge there is no way to do that using the Qt progress bar class, you'd have to design your own widget.

  • You should be able to achieve this effect using style sheets.

  • hello Andre thanks a lot... now i am able to display progress bar with two different colors at a time using style sheets.
    progress->setStyleSheet(QString("QProgressBar::chunk:horizontal {background: qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 grey, stop: 1 grey);}")+QString("QProgressBar::horizontal {border: 1px solid gray; border-radius: 3px; background: yellow; padding: 0px; text-align: left; margin-right: 4ex;}"));

Log in to reply