PyQt/QScrollBar/StyleScrollBar.py
2021-07-13 14:52:26 +08:00

47 lines
1.3 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2018年1月20日
@author: Irony
@site: https://pyqt.site , https://github.com/PyQt5
@email: 892768447@qq.com
@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_())