PyQt5 – Auto Adjusting Progress Bar size
Last Updated :
23 Jan, 2023
In this article we will see how to adjust the size of progress bar. Adjusting size means setting the size of progress bar as much as it is needed, nor too big nor too small, just the size which can comprise all the text in it. In order to do this we will use adjustSize method. Note : Adjusting size will set the minimum required size. It doesn’t depend on the text added using setFormat method.
Syntax : bar.adjustSize() Argument : It takes no argument. Action performed : It will adjust the size according to the need.
Below is the implementation.
Python3
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 , 20 , 50 )
bar.setValue( 100 )
bar.setAlignment(Qt.AlignCenter)
bar.adjustSize()
App = QApplication(sys.argv)
window = Window()
sys.exit(App. exec ())
|
Output :
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...