tobby48 4 роки тому
джерело
коміт
b756646fe9

+ 47
- 0
src/kr/co/swh/lecture/python/pyqt5/drawing/lineDraw.py Переглянути файл

@@ -0,0 +1,47 @@
1
+from PyQt5.QtWidgets import QMainWindow, QApplication, QDesktopWidget
2
+from PyQt5.QtCore import Qt
3
+from PyQt5.QtWidgets import *
4
+from PyQt5.QtGui import QPainter, QBrush, QPen
5
+import sys
6
+
7
+class Main(QMainWindow):
8
+    
9
+    def __init__(self):
10
+        super().__init__()
11
+
12
+        self.setMouseTracking(True)
13
+
14
+        self.setWindowTitle('mouse')
15
+        self.resize(640, 240)
16
+        self.xylist=[]
17
+        self.clicked = False
18
+        self.show()
19
+
20
+    def mousePressEvent(self, e):  # e ; QMouseEvent
21
+        if e.buttons() & Qt.LeftButton:
22
+            self.xylist = []
23
+            self.clicked = True
24
+
25
+    def mouseReleaseEvent(self, e):  # e ; QMouseEvent
26
+        print('BUTTON RELEASE')
27
+#         self.mouseButtonKind(e.buttons())
28
+        
29
+    def mouseMoveEvent(self, e):  # e ; QMouseEvent
30
+#         print('(%d %d)' % (e.x(), e.y()))
31
+        if self.clicked:
32
+            self.xylist.append((e.x(), e.y()))
33
+            self.repaint()
34
+
35
+    def paintEvent(self, event):
36
+        if not (self.x == -1 or self.y == -1):
37
+            if len(self.xylist) > 1:
38
+                q = QPainter(self)
39
+                q.begin(self)
40
+                for b in range(len(self.xylist)-1):
41
+                    q.drawLine(self.xylist[b][0], self.xylist[b][1], self.xylist[b+1][0], self.xylist[b+1][1])
42
+                q.end()
43
+
44
+
45
+App = QApplication(sys.argv)
46
+window = Main()
47
+sys.exit(App.exec())