Open In App

PyQt5 – Progress Bar with Dotted border

Last Updated : 22 Apr, 2020
Like Article

In this article we will see how we can create dotted border to a progress bar. By default the border of progress bar is continuous. Below is the representation of normal border progress bar vs the dotted border progress bar.

In order to this we have to change the CSS style sheet, below is the style sheet code which can be used with setStyleSheet method.

border : 3px black;
border-style : dotted;

Below is the implementation.

# importing libraries
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):
        # setting title
        self.setWindowTitle("Python ")
        # setting background color to window
        # self.setStyleSheet("background-color : yellow")
        # setting geometry
        self.setGeometry(100, 100, 600, 400)
        # calling method
        # showing all the widgets
    # method for widgets
    def UiComponents(self):
        # creating progress bar
        bar = QProgressBar(self)
        # setting geometry to progress bar
        bar.setGeometry(200, 100, 200, 30)
        # setting the value
        value = 70
        # setting alignment to center
        # setting dotted border
        bar.setStyleSheet("QProgressBar "
                          "border : 3px black;"
                          "border-style :dotted"
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app

Output :

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads