PyQt5 – 为状态栏设置皮肤
与设置背景图片不同,皮肤会根据状态栏的大小来调整自己。在背景图片中,如果图片的尺寸很大,而状态栏的尺寸很小,那么只有图片的那部分可以显示,这部分包括状态栏的尺寸。为状态栏设置皮肤的主要原因是,状态栏的高度相对来说比普通图片要小,这就是为什么不使用背景图片而使用皮肤的原因。
背景和皮肤将看起来像这样:
语法: self.statusBar().setStyleSheet(“border-image : url(skin.png);”)
参数: 它使用字符串作为参数。
执行的操作: 它为状态栏设置皮肤。
代码。
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 skin to status bar
self.statusBar().setStyleSheet("border-image : url(skin.png);")
# 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())
输出 :