PyQt5 控件样式表 QSS基础 案例
QSS (Qt Style Sheets)
用于设置控件的样式
类似于CSS
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QHBoxLayout, QPushButton, QMessageBox, QApplication, QVBoxLayout, QWidget, \
QLabel, QGridLayout, QLineEdit, QTextEdit, QFormLayout
'''
PyQt5 控件样式表 QSS基础 案例
QSS (Qt Style Sheets)
用于设置控件的样式
类似于CSS
'''
class BasicQSSDemo(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
# 设置定位和左上角坐标
self.setGeometry(300, 300, 360, 260)
# 设置窗口标题
self.setWindowTitle('QSS样式 的演示')
# 设置窗口图标
# self.setWindowIcon(QIcon('../web.ico'))
btn1 = QPushButton(self)
btn1.setText('按钮1')
btn2 = QPushButton(self)
btn2.setText('按钮2')
vbox = QVBoxLayout()
vbox.addWidget(btn1)
vbox.addWidget(btn2)
self.setLayout(vbox)
if __name__ == '__main__':
app = QApplication(sys.argv)
# 设置应用图标
app.setWindowIcon(QIcon('../web.ico'))
w = BasicQSSDemo()
qssStyle = '''
QPushButton {
background-color:red;
}
'''
w.setStyleSheet(qssStyle)
w.show()
sys.exit(app.exec_())