Friday, September 5, 2025
HomeLanguagesPyQt5 – Access the size of Status Bar

PyQt5 – Access the size of Status Bar

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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6750 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6701 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS