Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from PyQt5.QtWidgets import *
- class Qscene(QGraphicsScene):
- def __init__(self, parent=None):
- super(Qscene, self).__init__(parent)
- def mousePressEvent(self, event):
- super(Qscene, self).mousePressEvent(event)
- self.xRect = event.scenePos().x()
- self.yRect = event.scenePos().y()
- def mouseReleaseEvent(self, event):
- super(Qscene, self).mouseReleaseEvent(event)
- QGraphicsScene.addRect(self,self.xRect,self.yRect,self.endX-
- self.xRect,self.endY-self.yRect)
- def mouseMoveEvent(self, event):
- super(Qscene, self).mouseMoveEvent(event)
- self.endX = event.scenePos().x()
- self.endY = event.scenePos().y()
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- window = QWidget()
- scene = Qscene()
- view = QGraphicsView()
- view.setScene(scene)
- hbox = QGridLayout()
- hbox.addWidget(view)
- window.setLayout(hbox)
- window.show()
- sys.exit(app.exec_())
Add Comment
Please, Sign In to add comment