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

前端 未结 3 1844
南方客
南方客 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:45

    First you have to draw the image. You can do this my making a QLabel widget and call setPixmap. You need to convert your QImage to QPixmap before doing this (you can use QPixmap.fromImage(img)).

    You can get mouse clicks by subclassing the QImage and intercepting mousePressEvent. Look up the pixel value with QImage.pixel().

提交回复
热议问题