/
New Text Document.txt
78 lines (62 loc) · 2.52 KB
/
New Text Document.txt
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
68
69
70
71
72
73
74
75
76
77
78
from PySide2.QtCore import QRect, Slot, qApp, QEvent
from PySide2.QtWidgets import QMainWindow, QApplication, QGraphicsScene, QGraphicsView, QPushButton, QWidget
from PySide2.QtCore import Qt, QPoint
from PySide2.QtGui import QImage, QPainter, QPen
from PySide2 import QtCore
import sys
from main_widget import Widget
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Assignment")
self.graphicview()
def graphicview(self):
button = QPushButton("Draw Text Boxes")
scene = QGraphicsScene()
# self.image = QImage(self.size(), QImage.Format_RGB32)
# self.image.fill(Qt.black)
scene.addWidget(button)
view = QGraphicsView(self)
view.setScene(scene)
view.setGeometry(0, 0, 800, 600)
# self.setCentralWidget(view)
button.clicked.connect(self.buttonClicked)
# self.view.viewport().installEventFilter(self)
self.show()
# self.drawing = False
# self.brushSize = 2
# self.brushColor = Qt.black
# self.lastPoint = QPoint()
def mousePressEvent(self, event):
# super(MainWindow, self).mousePressEvent(event)
if event.button() == Qt.LeftButton:
self.drawing = True
self.startPoint = event.pos()
def mouseReleaseEvent(self, event):
if (Qt.LeftButton & self.drawing):
print(self.brushColor)
self.lastPoint = event.pos()
print(self.lastPoint)
painter = QPainter()
painter.setPen(QPen(self.brushColor, self.brushSize, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
self.scene.addItem(painter.drawRect(QtCore.QRect(self.startPoint, self.lastPoint)))
# self.update()
# def paintEvent(self, event):
# canvasPainter = QPainter(self)
# canvasPainter.drawImage(self.rect())
def buttonClicked(self):
self.button.hide()
# def eventFilter(self, obj, event):
# if obj is self.view.viewport():
# if event.type() == QEvent.MouseButtonPress:
# pass
# elif event.type() == QEvent.MouseButtonRelease:
# self.mouseReleaseEvent(event)
# print('mouse release event = ', event.pos())
# return QWidget.eventFilter(self, obj, event)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.resize(800, 600)
# window.show()
sys.exit(app.exec_())