-
Notifications
You must be signed in to change notification settings - Fork 0
/
threadtest.py
58 lines (50 loc) · 2.06 KB
/
threadtest.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
from PyQt5 import QtGui
from PyQt5.QtWidgets import QApplication, QDialog, QProgressBar, QPushButton, QVBoxLayout
import sys
from PyQt5.QtCore import Qt, QThread, pyqtSignal
import time
class MyThread(QThread):
# Create a counter thread
change_value = pyqtSignal(int)
def run(self):
cnt = 0
while cnt<100:
cnt+=1
time.sleep(0.3)
self.change_value.emit(cnt)
class Window(QDialog):
def __init__(self):
super().__init__()
self.title = "PyQt5 ProgressBar"
self.top = 200
self.left = 500
self.width = 300
self.height = 100
self.setWindowIcon(QtGui.QIcon("icon.png"))
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
vbox = QVBoxLayout()
self.progressbar = QProgressBar()
#self.progressbar.setOrientation(Qt.Vertical)
self.progressbar.setMaximum(100)
self.progressbar.setStyleSheet("QProgressBar {border: 2px solid grey;border-radius:8px;padding:1px}"
"QProgressBar::chunk {background:yellow}")
#qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 red, stop: 1 white);
#self.progressbar.setStyleSheet("QProgressBar::chunk {background: qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 red, stop: 1 white); }")
#self.progressbar.setTextVisible(False)
vbox.addWidget(self.progressbar)
self.button = QPushButton("Start Progressbar")
self.button.clicked.connect(self.startProgressBar)
self.button.setStyleSheet('background-color:yellow')
vbox.addWidget(self.button)
self.setLayout(vbox)
self.show()
def startProgressBar(self):
self.thread = MyThread()
self.thread.change_value.connect(self.setProgressVal)
self.thread.start()
def setProgressVal(self, val):
self.progressbar.setValue(val)
App = QApplication(sys.argv)
window = Window()
sys.exit(App.exec())