PyQt5基础学习-加载QSS文件 1.win.setStyleSheet(读入加载好的QSS文件)
使用win.setStyleSheet来加载读入CSS语句,从而做界面的样式
LoadQSS.py
""" 转载QSS文件 """ import sys from PyQt5.QtWidgets import * from CommonHelper import CommonHelper class MainWindow(QMainWindow): def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.resize(477, 258) self.setWindowTitle("加载QSS文件") btn = QPushButton() btn.setText('装载QSS文件') btn.setToolTip("提示文本") vbox = QVBoxLayout() vbox.addWidget(btn) btn.clicked.connect(self.onClick) self.setLayout(vbox) widget = QWidget(self) self.setCentralWidget(widget) widget.setLayout(vbox) def onClick(self): styleFile = "./style.qss" qssStyle = CommonHelper.readQSS(styleFile) win.setStyleSheet(qssStyle) if __name__ == "__main__": app = QApplication(sys.argv) win = MainWindow() win.show() sys.exit(app.exec_())
每天更新pyQt5内容