Pyqt5 外部加载QSS文件出错
本帖最后由 ChenpiT 于 2019-1-24 17:56 编辑Qss Files: styleSheey]t.qss
QPushButton{
background:#F76677;
border-radius:5px;
}
QPushButton#Btn2{
background:rgb(102, 194, 247);
border-radius:5px;
}
main.py
from PyQt5.QtWidgets import QApplication, QHBoxLayout, QVBoxLayout, QDialog, QGroupBox, QPushButton
from PyQt5 import QtGui, QtCore
import sys
class Window(QDialog):
def __init__(self):
super().__init__()
self.initWindow()
def initWindow(self):
self.setWindowTitle("example")
self.setGeometry(700, 400, 450, 150)
self.pushButton()
vbox = QVBoxLayout()
vbox.addLayout(self.hbox)
self.setLayout(vbox)
self.show()
def pushButton(self):
self.hbox = QHBoxLayout()
self.Btn1 = QPushButton('Btn1')
self.Btn1.setFont(QtGui.QFont('Sanserif', 10))
self.hbox.addWidget(self.Btn1)
self.Btn2 = QPushButton('Btn2')
self.Btn2.setFont(QtGui.QFont('Sanserif', 10))
self.hbox.addWidget(self.Btn2)
self.Btn3 = QPushButton('Btn3')
self.Btn3.setFont(QtGui.QFont('Sanserif', 10))
self.hbox.addWidget(self.Btn3)
def readQssFile(self, filePath):
with open(filePath, 'r', encoding='utf-8') as fileObj:
styleSheet = fileObj.read()
return styleSheet
if __name__ == "__main__":
app = QApplication(sys.argv)
window = Window()
styleSheet = window.readQssFile('./styleSheet.qss')
window.setStyleSheet(styleSheet)
sys.exit(app.exec_())
QSS如何指定类成员的id,使Btn2显示蓝色,其他为红色? 顶一下 学习 self.Btn2设置对象名即可QAQ
self.Btn2.setObjectName('Btn2')
看看 好难啊
有点看不懂。。。。
学习学习 谢谢你的 分享 难 顶上去 {:10_243:}
页:
[1]