python pyqt5 加载QSS

-- coding: utf-8 --

"""
【简介】
加载QSS文件

"""
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QVBoxLayout, QPushButton

class CommonHelper:
def init(self):
pass

@staticmethod
def readQss(style):
    with open(style, 'r') as f:
        return f.read()

class MainWindow(QMainWindow):
def init(self, parent=None):
super(MainWindow, self).init(parent)
self.resize(477, 258)
self.setWindowTitle("加载QSS文件")
btn1 = QPushButton(self)
btn1.setText('添加')
btn1.setToolTip('测试提示')
vbox = QVBoxLayout()
vbox.addWidget(btn1)

    self.setLayout(vbox)

if name == "main":
app = QApplication(sys.argv)
win = MainWindow()

styleFile = './style.qss'
qssStyle = CommonHelper.readQss(styleFile)
win.setStyleSheet(qssStyle)
win.show()
sys.exit(app.exec_())

style.qss

QMainWindow{
border-image:url(./images/python.jpg);

}

QToolTip{
border: 1px solid rgb(45, 45, 45);
background: white;
color: red;
}

你可能感兴趣的:(python pyqt5 加载QSS)