Skip to content
Related Articles

Related Articles

PyQt5 – Set fixed length for width/height of Status Bar

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

When window is resized status bar also get resized although we can set a fix size of status bar by using setFixedSize method with object of status bar. In this article we will see how we can only fix the length of wither width or height i.e other side would be variable.

In order to fix length of width we use setFixedWidth with object of status bar and to fix length of height we use setFixedHeight with object of status bar.

Syntax :


Argument : Both methods take integer as argument.

Action performed :
setFixedHeight fix the height of status bar.
setFixedWidth fix the width of status bar.

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 and padding with different sizes
        self.statusBar().setStyleSheet("border :3px solid black;")
        # setting fixed width
        # 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 :

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!