QtThreading

This commit is contained in:
Irony 2019-03-08 13:19:03 +08:00
parent 7d1a9ca119
commit ec891bde34
4 changed files with 79 additions and 1 deletions

View file

@ -9,6 +9,7 @@ encoding//Demo/Lib/FramelessWindow.py=utf-8
encoding//Demo/NativeEvent.py=utf-8
encoding//Demo/Notification.py=utf-8
encoding//Demo/ProbeWindow.py=utf-8
encoding//Demo/QtThreading.py=utf-8
encoding//Demo/RestartWindow.py=utf-8
encoding//Demo/SharedMemory.py=utf-8
encoding//Demo/SingleApplication.py=utf-8

70
Demo/QtThreading.py Normal file
View file

@ -0,0 +1,70 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2019年3月8日
@author: Irony
@site: https://pyqt5.com https://github.com/892768447
@email: 892768447@qq.com
@file: Threading.QtThreading
@description:
"""
from threading import Thread
from time import sleep
from PyQt5.QtCore import QObject, pyqtSignal, QTimer, Qt
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QProgressBar
__Author__ = """By: Irony
QQ: 892768447
Email: 892768447@qq.com"""
__Copyright__ = 'Copyright (c) 2019 Irony'
__Version__ = 1.0
class _Signals(QObject):
updateProgress = pyqtSignal(int)
Signals = _Signals()
class UpdateThread(Thread):
def run(self):
self.i = 0
for i in range(101):
self.i += 1
Signals.updateProgress.emit(i)
sleep(1)
self.i = 0
Signals.updateProgress.emit(i)
class Window(QWidget):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
self.resize(400, 400)
layout = QVBoxLayout(self)
self.progressBar = QProgressBar(self)
layout.addWidget(self.progressBar)
Signals.updateProgress.connect(
self.progressBar.setValue, type=Qt.QueuedConnection)
QTimer.singleShot(2000, self.doStart)
def doStart(self):
self.updateThread = UpdateThread(daemon=True)
self.updateThread.start()
if __name__ == '__main__':
import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())

View file

@ -138,4 +138,11 @@ PyQt 结合 Opencv 进行人脸检测;
3. [dlib-19.4.0.win32-py3.5.exe](Data/dlib-19.4.0.win32-py3.5.exe)
4. [shape-predictor-68-face-landmarks.dat.bz2](http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2)
![FacePoints](ScreenShot/FacePoints.png)
![FacePoints](ScreenShot/FacePoints.png)
## 16、使用Threading
[运行 QtThreading.py](QtThreading.py)
在PyQt中使用Theading线程
![QtThreading](ScreenShot/QtThreading.gif)

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB