Skip to content
Related Articles

Related Articles

PyQt5 – Capsule shaped Progress Bar
  • Last Updated : 22 Apr, 2020

In this article we will see how to create capsule shaped progress bar. By default when we create progress bar, it is in rectangular shape although we can change the shape with the help of resize method. But this will only allows to change the shape from rectangle to square. Below is representation of normal progress bar vs the capsule shaped progress bar.

In order to do so we have to change the radius of the border of both background and the bar of progress bar, this is done by changing the CSS style sheet, below is the style sheet code.

border: solid grey;
border-radius: 15px;
color: black;
background-color: #05B8CC;
border-radius :15px;

This style sheet is used which setStyleSheet method, 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
        # setting alignment to center
        # setting background to color and radius
        # and bar color and bar radius
                          "border: solid grey;"
                          "border-radius: 15px;"
                          " color: black; "
                          "QProgressBar::chunk "
                          "{background-color: # 05B8CC;"
                          "border-radius :15px;"
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app

Output :

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :