PyQt5 – 将皮肤设置为状态栏
与设置背景图像不同,皮肤会根据状态栏的大小自行调整。在背景图像中,如果图像尺寸较大且状态栏尺寸较小,则只有包含状态栏尺寸的图像部分是可显示的。将皮肤设置为状态栏的主要原因是,状态栏的高度比普通图像要小,这就是为什么最好不要使用背景图像皮肤。
背景和皮肤将如下所示:
Syntax : self.statusBar().setStyleSheet(“border-image : url(skin.png);”)
Argument : It takes string as argument.
Action performed : It sets skin to status bar.
代码 :
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())
输出 :