已定义好一份QSS在pyqt5代码中如何进行使用qss
时间: 2024-01-22 10:17:59 浏览: 79
PYQT5插入HTML演示.zip_PYQT5插入HTML演示_pyqt5_qss
可以通过以下步骤使用已定义好的QSS文件:
1.导入QSS文件
```
import os
import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = './plugins' #设置环境变量
qss = open('style.qss', 'r')
app.setStyleSheet(qss.read())
```
2.应用QSS样式
```
button = QPushButton('Button 1')
button.setObjectName('myButton')
```
3.在QSS文件中定义样式
```
#myButton {
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #f6f7fa, stop: 1 #dadbde);
border: 1px solid #dadbde;
border-radius: 3px;
padding: 5px;
margin-right: 10px;
}
```
阅读全文