|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 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显示蓝色,其他为红色?
|
|