forked from PyQt5/PyQt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleStyle.py
105 lines (86 loc) · 2.78 KB
/
SimpleStyle.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2018年1月30日
@author: Irony."[讽刺]
@site: https://pyqt5.com , https://github.com/892768447
@email: [email protected]
@file: SimpleStyle
@description:
'''
from random import randint
import sys
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QWidget, QApplication, QVBoxLayout, QProgressBar
__Author__ = "By: Irony.\"[讽刺]\nQQ: 892768447\nEmail: [email protected]"
__Copyright__ = "Copyright (c) 2018 Irony.\"[讽刺]"
__Version__ = "Version 1.0"
StyleSheet = '''
/*设置红色进度条*/
#RedProgressBar {
text-align: center; /*进度值居中*/
}
#RedProgressBar::chunk {
background-color: #F44336;
}
#GreenProgressBar {
min-height: 12px;
max-height: 12px;
border-radius: 6px;
}
#GreenProgressBar::chunk {
border-radius: 6px;
background-color: #009688;
}
#BlueProgressBar {
border: 2px solid #2196F3;/*边框以及边框颜色*/
border-radius: 5px;
background-color: #E0E0E0;
}
#BlueProgressBar::chunk {
background-color: #2196F3;
width: 10px; /*区块宽度*/
margin: 0.5px;
}
'''
class ProgressBar(QProgressBar):
def __init__(self, *args, **kwargs):
super(ProgressBar, self).__init__(*args, **kwargs)
self.setValue(0)
if self.minimum() != self.maximum():
self.timer = QTimer(self, timeout=self.onTimeout)
self.timer.start(randint(1, 3) * 1000)
def onTimeout(self):
if self.value() >= 100:
self.timer.stop()
self.timer.deleteLater()
del self.timer
return
self.setValue(self.value() + 1)
class Window(QWidget):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
self.resize(800, 600)
layout = QVBoxLayout(self)
layout.addWidget(
ProgressBar(self, minimum=0, maximum=100, objectName="RedProgressBar"))
layout.addWidget( # 繁忙状态
ProgressBar(self, minimum=0, maximum=0, objectName="RedProgressBar"))
layout.addWidget(
ProgressBar(self, minimum=0, maximum=100, textVisible=False,
objectName="GreenProgressBar"))
layout.addWidget(
ProgressBar(self, minimum=0, maximum=0, textVisible=False,
objectName="GreenProgressBar"))
layout.addWidget(
ProgressBar(self, minimum=0, maximum=100, textVisible=False,
objectName="BlueProgressBar"))
layout.addWidget(
ProgressBar(self, minimum=0, maximum=0, textVisible=False,
objectName="BlueProgressBar"))
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setStyleSheet(StyleSheet)
w = Window()
w.show()
sys.exit(app.exec_())