Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from PyQt5.QtCore import Qt,QTimer
- from PyQt5.QtWidgets import QWidget, QApplication
- from PyQt5.QtGui import QPixmap, QPainter, QPen, QColor, QPainterPath,QTransform
- class Menu(QWidget):
- def __init__(self):
- super().__init__()
- self.drawingPath = QPainterPath()
- self.image = QPixmap(r"C:UserswwwDesktopcar.jpg")
- self.resize(900,500)
- self.show()
- def paintEvent(self, event):
- painter = QPainter(self)
- painter.drawPixmap(self.rect(), self.image)
- if self.drawingPath:
- painter.setPen(QPen(QColor(121,252,50,150), 10 , Qt.SolidLine, Qt.RoundCap,Qt.RoundJoin))
- painter.drawPath(self.drawingPath)
- def mousePressEvent(self, event):
- self.previous_path = self.drawingPath
- if event.button() == Qt.LeftButton:
- # start a new QPainterPath and *move* to the current point
- self.drawingPath.moveTo(event.pos())
- print(self.drawingPath.elementCount())
- print( self.drawingPath )
- def mouseMoveEvent(self, event):
- if event.buttons() and Qt.LeftButton and self.drawingPath:
- # add a line to the painter path, without "removing" the pen
- self.lastline = event.pos()
- self.drawingPath.lineTo(self.lastline)
- self.update()
- def mouseReleaseEvent(self, event):
- return; # skip draw
- if event.button() == Qt.LeftButton and self.drawingPath:
- # draw the painter path to the pixmap
- painter = QPainter(self.image)
- painter.setPen(QPen(QColor(121,252,50,50), 20, Qt.SolidLine))
- painter.drawPath(self.drawingPath)
- self.drawingPath = None
- self.update()
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- mainMenu = Menu()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement