Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. import sys
  2. from PyQt5 import QtWidgets, uic
  3. from PyQt5.QtGui import QPainter, QColor, QBrush
  4. from PyQt5.QtCore import Qt
  5. Ui_MainWindow, QtBaseClass = uic.loadUiType("Op5.ui")
  6.  
  7. class CFilledRect:
  8. def __init__(self, x, y, width, height, brush):
  9. self._x = x
  10. self._y = y
  11. self._width = width
  12. self._height = height
  13. self._brush = brush
  14. self._r = 0
  15. self._g = 0
  16. self._b = 0
  17. def draw(self, scene):
  18. item = QtWidgets.QGraphicsRectItem(0,0,self._x, self._y)
  19. item.setBrush(self._brush)
  20. scene.addItem(item)
  21.  
  22.  
  23.  
  24.  
  25. class MyApp(QtWidgets.QMainWindow):
  26. def __init__(self):
  27. self._allRects = []
  28. self._allRemoved = []
  29. super(MyApp, self).__init__()
  30. self.ui = Ui_MainWindow()
  31. self.ui.setupUi(self)
  32. self._scene = QtWidgets.QGraphicsScene()
  33. self._scene.setSceneRect(0,0,100,100)
  34. self.ui.graphicsView.setScene(self._scene)
  35. self.ui.graphicsView.mousePressEvent = self.mouseDown
  36. self.ui.pushButton.clicked.connect(self.allRemoved)
  37. self.ui.pushButton_2.clicked.connect(self.allRedraw)
  38.  
  39. def allRemoved(self):
  40. print("Yeet")
  41. self._allRemoved = self._allRects
  42. self._allRects = []
  43. self._scene.clear()
  44.  
  45. def allRedraw(self):
  46. for C in self._allRemoved:
  47. C.draw(self._scene)
  48. print("Yeet")
  49.  
  50.  
  51.  
  52. def mouseDown(self, event):
  53. point = self.ui.graphicsView.mapToScene(event.pos())
  54. self._x = point.x()
  55. self._y = point.y()
  56. r = self.ui.horizontalSlider.value()
  57. g = self.ui.horizontalSlider_2.value()
  58. b = self.ui.horizontalSlider_3.value()
  59. self._brush = QBrush(QColor.fromRgb(r,g,b), Qt.SolidPattern)
  60. C1 = CFilledRect(self._x,self._y,0,0,self._brush)
  61. self._allRects.append(C1)
  62. C1.draw(self._scene)
  63. print(self._x)
  64.  
  65.  
  66.  
  67. if __name__ == "__main__":
  68. app = 0 # lost Kernal died probeem op bij herhaald opstarten
  69. app = QtWidgets.QApplication(sys.argv)
  70. window = MyApp()
  71. window.show()
  72. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement