Guest User

Untitled

a guest
May 23rd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import sys
  2. from PyQt5.QtWidgets import *
  3.  
  4. class Qscene(QGraphicsScene):
  5.  
  6. def __init__(self, parent=None):
  7. super(Qscene, self).__init__(parent)
  8.  
  9.  
  10.  
  11. def mousePressEvent(self, event):
  12. super(Qscene, self).mousePressEvent(event)
  13.  
  14. self.xRect = event.scenePos().x()
  15. self.yRect = event.scenePos().y()
  16.  
  17.  
  18. def mouseReleaseEvent(self, event):
  19. super(Qscene, self).mouseReleaseEvent(event)
  20. QGraphicsScene.addRect(self,self.xRect,self.yRect,self.endX-
  21. self.xRect,self.endY-self.yRect)
  22.  
  23. def mouseMoveEvent(self, event):
  24. super(Qscene, self).mouseMoveEvent(event)
  25. self.endX = event.scenePos().x()
  26. self.endY = event.scenePos().y()
  27.  
  28.  
  29. if __name__ == '__main__':
  30.  
  31. app = QApplication(sys.argv)
  32. window = QWidget()
  33. scene = Qscene()
  34. view = QGraphicsView()
  35. view.setScene(scene)
  36.  
  37. hbox = QGridLayout()
  38. hbox.addWidget(view)
  39.  
  40. window.setLayout(hbox)
  41. window.show()
  42.  
  43. sys.exit(app.exec_())
Add Comment
Please, Sign In to add comment