PyQt5 – 为状态栏的宽度/高度设置最小长度

PyQt5 – 为状态栏的宽度/高度设置最小长度

当我们创建一个状态栏时,默认情况下,状态栏的大小是可调整的。虽然我们可以使用状态栏的setMinimumSize()方法来设置状态栏的最小尺寸,但如果我们只想设置宽度或高度的最小长度,怎么办?

为了做到这一点,我们使用状态栏的setMinimumWidth()方法来设置最小宽度,使用状态栏的setMinimumHeight()方法来设置最小高度,当我们使用这些方法时,其他长度是可变的,即没有最小长度,它可以尽可能地缩小。

语法:

self.statusBar().setMinimumWidth(width)
self.statusBar().setMinimumHeight(height)

参数:

都以整数作为参数。

执行的操作:

setMinimumWidth() 设置最小宽度。

setMinimumHeight() 设置最小高度。

代码。

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 minimum Height of status bar
        self.statusBar().setMinimumHeight(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())

输出:

PyQt5 - 为状态栏的宽度/高度设置最小长度

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程