forked from PyQt5/PyQt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StyleScrollBar.py
47 lines (39 loc) · 1.26 KB
/
StyleScrollBar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2018年1月20日
@author: Irony
@site: https://pyqt.site , https://github.com/PyQt5
@email: [email protected]
@file: ScrollBar
@description:
"""
import chardet
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
class Window(QTextEdit):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
self.resize(800, 600)
# 设置横向纵向滚动条总是显示
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
with open("Data/ScrollBar.qss", "rb") as fp:
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
app = QApplication(sys.argv)
app.setApplicationName("滚动条样式")
app.setApplicationDisplayName("滚动条样式")
window = Window()
window.show()
sys.exit(app.exec_())