Pyqt get pixel position and value when mouse click on the image

前端 未结 3 1857
南方客
南方客 2021-02-06 09:41

I would like to know how i can select a pixel with a mouse click in an image (QImge) and get pixel position and value.

Thanks

3条回答
  •  春和景丽
    2021-02-06 10:46

    self.image = QLabel()
    self.image.setPixmap(QPixmap("C:\\myImg.jpg"))
    self.image.setObjectName("image")
    self.image.mousePressEvent = self.getPos
    
    def getPos(self , event):
        x = event.pos().x()
        y = event.pos().y() 
    

提交回复
热议问题