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
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
This question is old but for everybody getting here, like me, this is my solution based on Jareds answer:
Make sure the size of the label matches the size of the image, otherwise the x and y mouse coords need to be transformed to image coords. And I guess it's also possible to use the
.pixel()
method directly on a pixmap as well, but the QImage object seems to perform better in my case.First you have to draw the image. You can do this my making a
QLabel
widget and callsetPixmap
. You need to convert yourQImage
toQPixmap
before doing this (you can useQPixmap.fromImage(img)
).You can get mouse clicks by subclassing the
QImage
and interceptingmousePressEvent
. Look up the pixel value withQImage.pixel()
.