PyQt5 – Image bar as Progress Bar
Last Updated :
22 Apr, 2020
In this article we will see how to add image to bar of progress bar. We can set the background image but in order to set image to a bar we have to modify the progress bar chunk CSS, below is how normal background image and background image to a bar looks like.

In order to do this below is the CSS style sheet for chunk file
QProgressBar::chunk
{
background-image : url(image.png);
}
This style sheet is used by setStyleSheet method, 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(70)
bar.setAlignment(Qt.AlignCenter)
bar.setStyleSheet(
"QProgressBar::chunk "
"{"
"background-image: url(image.png);"
"}"
)
App = QApplication(sys.argv)
window = Window()
sys.exit(App.exec())
|
Output :

Please Login to comment...