Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. import sys
  2. from PyQt5.QtCore import Qt,QTimer
  3. from PyQt5.QtWidgets import QWidget, QApplication
  4. from PyQt5.QtGui import QPixmap, QPainter, QPen, QColor, QPainterPath,QTransform
  5.  
  6.  
  7. class Menu(QWidget):
  8. def __init__(self):
  9. super().__init__()
  10. self.drawingPath = QPainterPath()
  11. self.image = QPixmap(r"C:UserswwwDesktopcar.jpg")
  12. self.resize(900,500)
  13. self.show()
  14.  
  15.  
  16. def paintEvent(self, event):
  17. painter = QPainter(self)
  18. painter.drawPixmap(self.rect(), self.image)
  19. if self.drawingPath:
  20. painter.setPen(QPen(QColor(121,252,50,150), 10 , Qt.SolidLine, Qt.RoundCap,Qt.RoundJoin))
  21. painter.drawPath(self.drawingPath)
  22.  
  23. def mousePressEvent(self, event):
  24. self.previous_path = self.drawingPath
  25. if event.button() == Qt.LeftButton:
  26. # start a new QPainterPath and *move* to the current point
  27. self.drawingPath.moveTo(event.pos())
  28. print(self.drawingPath.elementCount())
  29. print( self.drawingPath )
  30.  
  31. def mouseMoveEvent(self, event):
  32. if event.buttons() and Qt.LeftButton and self.drawingPath:
  33. # add a line to the painter path, without "removing" the pen
  34. self.lastline = event.pos()
  35. self.drawingPath.lineTo(self.lastline)
  36. self.update()
  37.  
  38. def mouseReleaseEvent(self, event):
  39. return; # skip draw
  40. if event.button() == Qt.LeftButton and self.drawingPath:
  41. # draw the painter path to the pixmap
  42. painter = QPainter(self.image)
  43. painter.setPen(QPen(QColor(121,252,50,50), 20, Qt.SolidLine))
  44. painter.drawPath(self.drawingPath)
  45. self.drawingPath = None
  46. self.update()
  47.  
  48.  
  49. if __name__ == '__main__':
  50. app = QApplication(sys.argv)
  51. mainMenu = Menu()
  52. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement