PyQt5支持css設置樣式,使用.setStyleSheet()方法。
比如為主窗口的一些部件設置一些通用樣式
self.setStyleSheet(
'QPushButton{font-weight: bold; background: skyblue; border-radius: 14px;' # 為按鈕設置通用樣式
'width: 64px; height: 28px; font-size: 20px; text-align: center;}'
'QPushButton:hover{background: rgb(50, 150, 255);}' # 鼠標划到按鈕上的樣式
'QLabel{font-weight: bold; font-size: 20px; color: orange}' # QLabel通用樣式
'QLineEdit{width: 100px; font: 微軟雅黑}' # QlineEdit通用樣式
)
比如為一個name_label設置樣式
gc_show_label.setStyleSheet('color: black; height: 28px; background: skyblue; border-radius: 14px;')
優先級是單獨部件的樣式 > 通用樣式