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.
QProgressBar
{
border: solid grey;
border-radius: 15px;
color: black;
}
QProgressBar::chunk
{
background-color: #05B8CC;
border-radius :15px;
}
This style sheet is used which 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"
"{"
"border: solid grey;"
"border-radius: 15px;"
" color: black; "
"}"
"QProgressBar::chunk "
"{background-color: # 05B8CC;"
"border-radius :15px;"
"}" )
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
Share your thoughts in the comments
Please Login to comment...