Open In App

PyQt5 – Access the size of Status Bar

Last Updated : 09 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article we will see how to access the size of status bar. We know that we can set the status bar size by using setFixedSize method with status bar object, in order to access the status bar size we will use size method with its object.

Notes: -> If size of status bar is not set it will return minimum size. -> If fixed size of status bar is set it will return fixed size. -> If minimum size of status bar is set it will return minimum size. -> If maximum size of status bar is set it will return minimum size.

Syntax : self.statusBar().size()

Argument : It takes no argument.

Return : It returns QSize object.

Code : 

Python3




from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
 
 
class Window(QMainWindow):
    def __init__(self):
        super().__init__()
 
        # set the title
        self.setWindowTitle("Python")
 
        # setting  the geometry of window
        self.setGeometry(60, 60, 600, 400)
 
        # setting status bar message
        self.statusBar().showMessage("This is status bar")
 
        # setting  border
        self.statusBar().setStyleSheet("border :3px solid black;")
 
        # setting fixed size
        self.statusBar().setFixedSize(400, 60)
 
        # getting size
        size = self.statusBar().size()
 
        # printing the size
        print(size)
 
        # creating a label widget
        self.label_1 = QLabel("status bar", self)
 
        # moving position
        self.label_1.move(100, 100)
 
        # setting up the border
        self.label_1.setStyleSheet("border :1px solid blue;")
 
        # resizing label
        self.label_1.adjustSize()
 
        # show all the widgets
        self.show()
 
 
# create pyqt5 app
App = QApplication(sys.argv)
 
# create the instance of our Window
window = Window()
 
 
# start the app
sys.exit(App.exec())


Output :

PyQt5.QtCore.QSize(400, 60)

pyqt-statusbar-size-method



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads