Qt World Summit: Submit your Presentation

Get pixel position under mouseclick in QGraphicsPixmapItem

  • What I want to achieve
    I want to create a QGraphicsViewer that can zoom in,out and get the position of a pixel under mouseclick from an image.

    What I did so far
    I've successfully created my QGraphicsViewer that can zoom in on the image.

    How to get the pixel position (X,Y) of the image under the mouseclick? A simple mouseclick event is not working as it's not taking into account that the image scales after zooming see image bellow.

    No Zoom: Notice the pixel at 2,2 at the top.
    0_1475741279787_Image 1.png

    After Zooming: pixel at 2,2 is different from the first image.
    0_1475741398703_Image 2.png

  • Solved it!

    Create a customScene, override mousepressevent and use scenePos().

Log in to reply