ROI wont update its handle coordinates when dragging

瀏覽次數:65 次
跳到第一則未讀訊息

Friedrich

未讀,
2018年2月14日 清晨5:08:142018/2/14
收件者: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

未讀,
2018年2月23日 凌晨2:38:172018/2/23
收件者: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

未讀,
2018年3月9日 中午12:47:532018/3/9
收件者:pyqtgraph
Thanks for this. I was just getting ready to do something very similar. 

jean Bilheux

未讀,
2018年3月22日 下午1:30:062018/3/22
收件者:pyqtgraph
Thanks a lot Friedrich. Me too, that will be very useful for my project.
回覆所有人
回覆作者
轉寄
0 則新訊息