Reputation: 630
I want to make a python script where I show an image and then the end user can draw an arrow over this image by clicking two points.
I would like the line to be an arrow, and to show it following the pointer of the mouse until the user click for the second time.
Working with Python3, PyQt4, Ubuntu.
Thanks in advance
Upvotes: 2
Views: 9139
Reputation: 6429
Use paintEvent and QPainter:
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
class Example(QWidget):
def __init__(self):
super().__init__()
self.setGeometry(30, 30, 500, 300)
def paintEvent(self, event):
painter = QPainter(self)
pixmap = QPixmap("myPic.png")
painter.drawPixmap(self.rect(), pixmap)
pen = QPen(Qt.red, 3)
painter.setPen(pen)
painter.drawLine(10, 10, self.rect().width() -10 , 10)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
ex.show()
sys.exit(app.exec_())
Upvotes: 3