PyQt/QScrollBar/StyleScrollBar.py

48 lines
1.3 KiB
Python
Raw Normal View History

2018-11-01 00:10:21 +08:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
2021-07-13 14:52:26 +08:00
"""
2018-11-01 00:10:21 +08:00
Created on 2018年1月20日
2021-07-13 14:52:26 +08:00
@author: Irony
@site: https://pyqt.site , https://github.com/PyQt5
2018-11-01 00:10:21 +08:00
@email: 892768447@qq.com
@file: ScrollBar
@description:
2021-07-13 14:52:26 +08:00
"""
2018-11-01 00:10:21 +08:00
import chardet
2021-07-13 14:52:26 +08:00
try:
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QTextEdit, QApplication
except ImportError:
from PySide2.QtCore import Qt
from PySide2.QtWidgets import QTextEdit, QApplication
2018-11-01 00:10:21 +08:00
class Window(QTextEdit):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
2018-12-31 14:49:29 +08:00
self.resize(800, 600)
2018-11-01 00:10:21 +08:00
# 设置横向纵向滚动条总是显示
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
2018-12-31 14:49:29 +08:00
with open("Data/ScrollBar.qss", "rb") as fp:
2018-11-01 00:10:21 +08:00
content = fp.read()
encoding = chardet.detect(content) or {}
content = content.decode(encoding.get("encoding") or "utf-8")
self.setText(content)
# 设置样式
self.setStyleSheet(content)
if __name__ == "__main__":
import sys
2021-07-13 14:52:26 +08:00
2018-11-01 00:10:21 +08:00
app = QApplication(sys.argv)
app.setApplicationName("滚动条样式")
app.setApplicationDisplayName("滚动条样式")
window = Window()
window.show()
sys.exit(app.exec_())