I am having trouble with the coordinates used to create a RectROI centered 
on the position of a mouse click.

For example if I have an image displayed:

import pyqtgraph as pg
import numpy as np

pw = pg.PlotWidget()
img = pg.ImageItem(np.random.normal(size=(400,400)))
pw.addItem(img)

then I can get us position of a user click by hooking into 
img.sigMouseClicked

img.sigMouseClicked.connect(drawRect)

def drawRect(pos):
   # img coordinates
   imc = img.mapFromScene(pos)
   width = 10
   height = 10

   rect = pg.RectROI(pos=, size=(width, height))
   pw.addItem(rect)


I am unsure of how to format the position of the rectangle such that the 
center is the coordinates of the mouse click (in image coordinates). The 
documentation suggests that the pos argument should be the coordinates of 
the lower left corner of the rectangle. However, do these coordinates need 
to be given in the scene coordinate system rather than the image coordinate 
system?

Would the correct transformation be as follows?

    pg.RectROI(pos=img.mapToScene(imc.x() - width/2, imc.y() + height/2), 
size=(width, height))

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/3ae815eb-c4e9-4990-9d42-baad6f9f8d23%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to