|
@@ -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())
|