When we create progress bar in PyQt5 by default the progress i.e the loading goes from left to right, but PyQt5 allows us to change its direction as well with the help of setInvertedAppearance
method. It takes bool as argument and make the progress bar inverted.
Below is how normal progress bar and inverted progress bar looks like
Syntax : bar.setInvertedAppearance(True)
Argument : It takes bool as argument.
Action performed : It set set the progress bar to inverted appearance.
# 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 ): super ().__init__() # setting title self .setWindowTitle( "Python " ) # setting geometry self .setGeometry( 100 , 100 , 600 , 400 ) # calling method self .UiComponents() # showing all the widgets self .show() # 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 bar.setValue( 70 ) # setting alignment to center bar.setAlignment(Qt.AlignCenter) # making progress bar inverted bar.setInvertedAppearance( True ) App = QApplication(sys.argv) # create the instance of our Window window = Window() # start the app sys.exit(App. exec ()) |
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.