When we create a progress bar, by default there is no background color set to it, although the bar color is of green. In this article we will see how to set the background color to the progress bar. Below is the representation of normal progress bar vs the progress bar which has background color.

In order to do this we have to change the CSS style sheet using setStyleSheet
method, below is the style sheet.
QProgressBar
{
background-color :lightblue;
border : 1px;
}
Below is the implementation.
from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
class Window(QMainWindow):
def __init__( self ):
super ().__init__()
self .setWindowTitle( "Python " )
self .setGeometry( 100 , 100 , 600 , 400 )
self .UiComponents()
self .show()
def UiComponents( self ):
bar = QProgressBar( self )
bar.setGeometry( 200 , 100 , 200 , 30 )
bar.setValue( 30 )
bar.setAlignment(Qt.AlignCenter)
bar.setStyleSheet( "QProgressBar"
"{"
"background-color : lightblue;"
"border : 1px"
"}" )
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
