Skip to content
Related Articles

Related Articles

PyQt5 – Access the size of Status Bar

Improve Article
Save Article
  • Last Updated : 22 Apr, 2020
Improve Article
Save Article

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 setFizedSize method with status bar object, in order to access the status bar size we will use size method with its object.

-> 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 :

from PyQt5.QtCore import * 
from PyQt5.QtGui import * 
from PyQt5.QtWidgets import * 
import sys
class Window(QMainWindow):
    def __init__(self):
        # set the title
        # 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
        # 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
        # show all the widgets
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app

Output :

PyQt5.QtCore.QSize(400, 60)


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!