from PyQt5.QtWidgets import *
import sys
class BasicQCSS(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("QSS样式/子控件选择器")
btn1 = QPushButton(self)
btn1.setText("按钮1")
btn1.setProperty("name", 'btn1')
btn2 = QPushButton(self)
btn2.setText("按钮2")
btn2.setProperty("name", 'btn2')
btn3 = QPushButton(self)
btn3.setText("按钮3")
btn3.setProperty("name", 'btn3')
combo = QComboBox(self)
combo.setObjectName("myComboBox")
combo.addItem("Windows")
combo.addItem("Linux")
combo.addItem("Mac OS X")
combo.move(50, 50)
vbox = QVBoxLayout()
vbox.addWidget(btn1)
vbox.addWidget(btn2)
vbox.addWidget(btn3)
vbox.addWidget(combo)
self.setLayout(vbox)
self.setGeometry(350, 200, 320, 150)
if __name__ == "__main__":
app = QApplication(sys.argv)
main = BasicQCSS()
# 选择器
# 将QComboBox的下拉图标更改为图片
qssStyle = '''
QPushButton[name='btn2'] {
background-color:red;
color:blue;
height:120;
font-size:60px;
}
QPushButton[name='btn3'] {
background-color:yellow;
color:red;
height:60;
font-size:30px;
}
QComboBox#myComboBox::drop-down{
image:url(./image/img1.png)
}
'''
main.setStyleSheet(qssStyle)
main.show()
sys.exit(app.exec_())
标签:__,控件,name,self,QSS,vbox,combo,选择器,btn2
From: https://www.cnblogs.com/jackchen28/p/18240717