PyQt5基础学习-指定特定的组件变换样式 1.QPushButton().setProperty(设置按钮的属性名)
通过设置主键的名字来构造特定按钮的组件
QSSSelector.py
""" 使用QSS选择器设置控件样式 """ from PyQt5.QtWidgets import * import sys class QSSSelector(QWidget): def __init__(self): super(QSSSelector, self).__init__() self.setWindowTitle("QSS样式") btn1 = QPushButton(self) btn1.setText("按钮1") btn2 = QPushButton(self) btn2.setProperty("name", "btn2") btn2.setText("按钮2") btn3 = QPushButton(self) btn3.setProperty("name", "btn3") btn3.setText("按钮3") vbox = QVBoxLayout() vbox.addWidget(btn1) vbox.addWidget(btn2) vbox.addWidget(btn3) self.setLayout(vbox) if __name__ == "__main__": app = QApplication(sys.argv) form = QSSSelector() #选择器 qssStyle = """ QPushButton[name="btn2"] { background-color:red; color:yellow; height:120; font-size:60px; } QPushButton[name="btn3"] { background-color:blue; color:yellow; height:60; font-size:30px; } """ form.setStyleSheet(qssStyle) form.show() sys.exit(app.exec_())
每天更新pyQt5内容