lianback 2020-04-30
PyQt5 给主窗口添加样式
#! /usr/bin/env python
# -*- coding:utf-8 -*-
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5.QtGui import QIcon
class M_Window(QMainWindow):
def __init__(self):
super().__init__()
self.resize(600,350)
self.status = self.statusBar()
# 状态栏可以设置显示时间,如果没有设置时间参数,状态栏将一直显示
self.status.showMessage("状态栏:给主窗口添加样式")
self.setWindowTitle("给主窗口添加样式")
self.setWindowIcon(QIcon("./icon/title.png"))
# 给主窗口添加样式
qssfile = open("./qss/mainstyle.qss", encoding="utf-8").read()
self.setStyleSheet(qssfile)
if __name__ == "__main__":
app = QApplication(sys.argv)
m_form = M_Window()
m_form.show()
sys.exit(app.exec_())
Qss文件
QMainWindow{
color:greenyellow;
background-color:rgb(34, 34, 229);
}
QWidget{
color:white;
}