用QSS给pyside6的风格变成暗黑
时间: 2024-04-22 11:05:37 浏览: 124
可以使用以下QSS样式来将PySide6的风格变成暗黑:
```python
import sys
from PySide6.QtWidgets import QApplication, QWidget
from PySide6.QtCore import QFile
if __name__ == '__main__':
app = QApplication(sys.argv)
# 创建窗口
window = QWidget()
# 加载QSS样式文件
qss_file = QFile('dark.qss')
qss_file.open(QFile.ReadOnly)
style_sheet = qss_file.readAll().data().decode()
qss_file.close()
# 设置QSS样式
window.setStyleSheet(style_sheet)
# 显示窗口
window.show()
sys.exit(app.exec_())
```
其中,dark.qss是以下样式文件:
```css
/* 暗黑主题 */
QWidget {
background-color: #333333;
color: #FFFFFF;
}
QLabel, QAbstractButton {
color: #FFFFFF;
}
QLabel {
border: none;
}
QPushButton {
background-color: #444444;
border: none;
padding: 5px 10px;
border-radius: 3px;
}
QPushButton:hover {
background-color: #555555;
}
QLineEdit {
background-color: #444444;
border: none;
padding: 5px;
border-radius: 3px;
color: #FFFFFF;
}
QLineEdit:focus {
border: 2px solid #00BFFF;
}
QScrollBar:vertical {
background: #444444;
width: 10px;
margin: 0px 0px 0px 0px;
}
QScrollBar::handle:vertical {
background: #FFFFFF;
min-height: 20px;
border-radius: 5px;
}
QScrollBar::add-line:vertical {
background: none;
height: 0px;
subcontrol-position: bottom;
subcontrol-origin: margin;
}
QScrollBar::sub-line:vertical {
background: none;
height: 0px;
subcontrol-position: top;
subcontrol-origin: margin;
}
QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {
background: none;
}
```
这样就可以将PySide6的风格变成暗黑主题了。
阅读全文