ROI wont update its handle coordinates when dragging

65 views
Skip to first unread message

Friedrich

unread,
Feb 14, 2018, 5:08:14 AM2/14/18
to pyqtgraph
heyho

i am fooling around with a PolyLineROI. when i add it to my viewbox and start moving it (to the desired position) it won't update the positions of its handles. even if it is at its new position and i am starting to drag the handles, the position-change is relative to its handles' original position.

import pyqtgraph as pg

def roiMove():
   """Print the coordinates of the ROI."""
   print(roi.getState()['points'])

win = pg.GraphicsWindow()
vb = win.addViewBox()
# roi in triangle shape
roi = pg.PolyLineROI([[1, 2], [1.5, 2], [1, 0]],
           closed=True,
           pen=pg.mkPen(color=(0, 201, 255, 255), width=3)
               )

# connect to printing function when moving something
# NOTE: when dragging the whole ROI the positions won't be updated
roi.sigRegionChanged.connect(roiMove)
vb.addItem(roi)
vb.setXRange(-5, 5)
vb.setYRange(-5, 5)
pg.QtGui.QApplication.exec_()




i feel like i am close to the solution or just missed some important point...

Friedrich

unread,
Feb 23, 2018, 2:38:17 AM2/23/18
to pyqtgraph
as it turns out, i really was close. instead of taking the points from the state, the handle postions needed to be mapped to parent. i adjusted the MWE for those who are interested:

import pyqtgraph as pg

def roiMove():
   """Print the coordinates of the ROI."""
   pts = roi.getSceneHandlePositions()
   print([roi.mapSceneToParent(pt[1]) for pt in pts])

win = pg.GraphicsWindow()
vb = win.addViewBox()
# roi in triangle shape
roi = pg.PolyLineROI([[1, 2], [1.5, 2], [1, 0]],
           closed=True,
           pen=pg.mkPen(color=(0, 201, 255, 255), width=3)
               )

# connect to printing function when moving something
roi.sigRegionChanged.connect(roiMove)
vb.addItem(roi)
vb.setXRange(-5, 5)
vb.setYRange(-5, 5)
pg.QtGui.QApplication.exec_()
Code hier eingeben...


Tim Williams

unread,
Mar 9, 2018, 12:47:53 PM3/9/18
to pyqtgraph
Thanks for this. I was just getting ready to do something very similar. 

jean Bilheux

unread,
Mar 22, 2018, 1:30:06 PM3/22/18
to pyqtgraph
Thanks a lot Friedrich. Me too, that will be very useful for my project.
Reply all
Reply to author
Forward
0 new messages