Sunday, November 17, 2024
Google search engine
HomeLanguagesPyQt5 – Set fixed length for width/height of Status Bar

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

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

self.statusBar().setFixedHeight(height)
self.statusBar().setFixedWidth(width)

Argument : Both methods take integer as argument. Action performed : setFixedHeight fix the height of status bar. setFixedWidth fix the width of status bar.

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

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

Most Popular

Recent Comments