There is a program that opens the image:
pixmap = QPixmap("pic.jpg") self.image = QLabel (self) self.image.setPixmap(pixmap) self.image.move(200,10) self.image.setObjectName("image") Next, by clicking on the image, it receives the coordinates of the point of the click. How to make the program put a point in these coordinates? Tried to do through the function:
pen = QPen(Qt.black,10) qp=QPainter(self.image) qp.setPen(pen) qp.drawPoint(x,y) Nothing comes, no errors, draws no points. Picture and drawing function in the same class. I use python3.4 , qt4 .
class MainGui(QWidget): def __init__(self): super().__init__() self.init_UI() def init_UI(self): self.pixmap = QPixmap("pic.jpg") self.image = QLabel (self) self.image.setPixmap(self.pixmap) self.image.move(200,10) self.image.setObjectName("image") self.image.mousePressEvent = self.get_pos def drawPoints(self, pos): pen = QPen(Qt.black,10) qp=QPainter(self.image) qp.setPen(pen) qp.begin (self.image) qp.drawPoint(pos.x(),pos.y()) self.image.update() def get_pos(self, event): X=event.pos().x() y=event.pos().y() self.drawPoints(event.pos()) if __name__ =='__main__': app = QApplication(sys.argv) ex = MainGui() ex.show() sys.exit(app.exec_())
qp.begin(self.image); qp.drawPoint(x,y); qp.end();qp.begin(self.image); qp.drawPoint(x,y); qp.end();- yrHeTaTeJlb