📜  PyQt5 - 将背景图片添加到状态栏

📅  最后修改于: 2022-05-13 01:54:51.912000             🧑  作者: Mango

PyQt5 - 将背景图片添加到状态栏

在本文中,我们将了解如何将背景图像设置为状态栏。我们可以在setStyleSheet()方法中使用background-color设置背景颜色,也可以在setStyleSheet()方法中使用background-image将背景图像设置为标签。

代码 :

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 with image")
  
        # setting background image to status bar
        self.statusBar().setStyleSheet("background-image : url(image.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())

输出 :
pyqt-background-statusBar