-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathBackingWidget.py
More file actions
67 lines (54 loc) · 1.64 KB
/
BackingWidget.py
File metadata and controls
67 lines (54 loc) · 1.64 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2025/12/27
@author: Irony
@site: https://pyqt.site | https://github.com/PyQt5
@email: 892768447@qq.com
@file: BackingWidget.py
@description:
"""
try:
from PyQt5.QtCore import pyqtSlot as Slot
from PyQt5.QtWidgets import QApplication, QWidget
except ImportError:
from PySide2.QtCore import Slot
from PySide2.QtWidgets import QApplication, QWidget
from Lib.BackingPaint import BackingPaint
class BackingWidget(QWidget):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._showed = False
self._thread = BackingPaint(self)
self.resize(800, 600)
def closeEvent(self, event):
if self._thread:
self._thread.stop()
self._thread.quit()
self._thread.wait(100)
del self._thread
super().closeEvent(event)
def showEvent(self, event):
super().showEvent(event)
if not self._showed:
self._showed = True
self._thread.start()
self._thread.resized.emit(self.width(), self.height())
def resizeEvent(self, event):
super().resizeEvent(event)
if self._showed and self._thread and self._thread.isRunning():
self._thread.resized.emit(self.width(), self.height())
def paintEngine(self):
return None
@Slot()
def paintOnGui(self):
if self._thread:
self._thread.paintOnGui()
if __name__ == "__main__":
import cgitb
import sys
cgitb.enable(format="text")
app = QApplication(sys.argv)
w = BackingWidget()
w.show()
sys.exit(app.exec_())