tobby48 4 gadus atpakaļ
vecāks
revīzija
6cc5497814

+ 2
- 2
src/kr/co/swh/lecture/python/pyqt5/drawing/lineDraw.py Parādīt failu

@@ -34,10 +34,10 @@ class Main(QMainWindow):
34 34
 
35 35
     def paintEvent(self, event):
36 36
         q = QPainter(self)
37
-#         q.begin(self)
37
+        q.begin(self)
38 38
         for b in range(len(self.xylist)-1):
39 39
             q.drawLine(self.xylist[b][0], self.xylist[b][1], self.xylist[b+1][0], self.xylist[b+1][1])
40
-#         q.end()
40
+        q.end()
41 41
 
42 42
 
43 43
 App = QApplication(sys.argv)

+ 49
- 0
src/kr/co/swh/lecture/python/pyqt5/drawing/lineDraw2.py Parādīt failu

@@ -0,0 +1,49 @@
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(900, 600)
16
+        self.xylist=[]
17
+        self.clicked = False
18
+        self.show()
19
+
20
+    def mousePressEvent(self, e):  # e ; QMouseEvent
21
+        print('BUTTON Press')
22
+        if e.buttons() & Qt.LeftButton:
23
+            self.xylist.append(list())
24
+            self.clicked = True
25
+
26
+    def mouseReleaseEvent(self, e):  # e ; QMouseEvent
27
+        print('BUTTON RELEASE')
28
+        self.clicked = False
29
+#         self.mouseButtonKind(e.buttons())
30
+        
31
+    def mouseMoveEvent(self, e):  # e ; QMouseEvent
32
+        print('(%d %d)' % (e.x(), e.y()))
33
+        if self.clicked:
34
+            self.xylist[-1].append((e.x(), e.y()))
35
+            self.repaint()  # self.update()와 결과 동일
36
+
37
+    def paintEvent(self, event):
38
+#                 q.begin(self)
39
+        if len(self.xylist)> 0:
40
+            q = QPainter(self)
41
+            for b in self.xylist:
42
+                for c in range(len(b)-1):
43
+                    q.drawLine(b[c][0], b[c][1], b[c+1][0], b[c+1][1])
44
+
45
+
46
+#                 q.end()
47
+App = QApplication(sys.argv)
48
+window = Main()
49
+sys.exit(App.exec())