Yeah, the way to do it is not to try and index the object, but to call the
.x() and .y() methods.


On Fri, Dec 10, 2021 at 01:28 Salvatore Lorusso <[email protected]> wrote:

> Hi Ogi,
>
> if I understand well you need to make some modification to the code.
> However I think that in my particular case I can still get rid of the
> problem using the modification of the code reported below. It seems that it
> works as well for pg.Point or QtCore.QPointF
>
> def roi_changed(roi):
>
>     Handles=roi.getLocalHandlePositions() # Get list of handles
>     for h in Handles:
>         position=h[1]
>         print(f'point = ({position.x():.4f},{position.y():.4f})')
> #-------------------------------------------------------------------
> import pyqtgraph as pg
>
> app = pg.mkQApp("Examples")
> win = pg.GraphicsLayoutWidget(show=True, size=(800,800), border=True)
> win.setWindowTitle('ROI Example')
>
> plot = win.addPlot()
> plot.setXRange(0,10)
> plot.setYRange(0,10)
>
> roi=pg.PolyLineROI([[5.0,2], [6.0, 2], [6.0, 5]], pen=(6,9), closed=False)
> plot.addItem(roi)
>
> roi.sigRegionChangeFinished.connect(lambda roi: roi_changed(roi))
>
> print('Print Handles position as they are created')
> Handles=roi.getLocalHandlePositions() # Get list of handles
> for h in Handles: # Print handles position
>     position=h[1]
>     print(f'point = ({position.x():.4f},{position.y():.4f})')
>
> print('... Then when I move one handle...')
>
> pg.exec()
>
> Do you agree?
>
> thanks
> Salvatore
>
> Il giorno giovedì 9 dicembre 2021 alle 21:42:05 UTC+1 [email protected]
> ha scritto:
>
>> Hi Salvatore,
>>
>> This one took me a bit to debug!  Pro-tip, if using breakpoint() use the
>> pyside bindings, not the PyQt ones.
>>
>> Issue is in the ROI.movePoint; or more specifically
>> QGraphicsItem.mapFromScene which takes a pg.Point as input, but returns a
>> QtCore.QPointF; easiest fix would be to modify the method such that
>> `h['pos'] = Point(newPos)` in the movePoint method of the ROI class.
>>
>>         elif h['type'] == 'f':
>>             newPos = self.mapFromParent(p1)
>>             h['item'].setPos(newPos)
>>             h['pos'] = Point(newPos)
>>             self.freeHandleMoved = True
>>
>> At a glance, I'm not sure if there are some other code-paths that would
>> suffer a similar issue.
>>
>> On Thu, Dec 9, 2021 at 11:39 AM Salvatore Lorusso <[email protected]>
>> wrote:
>>
>>> Hi all,
>>>
>>> I appreciate if someone has an answer to the following issue.
>>> Please consider the following code:
>>>
>>> def roi_changed(roi):
>>>
>>>     Handles=roi.getLocalHandlePositions() # Get list of handles
>>>     for h in Handles:
>>>         position=h[1]
>>>         print(position)
>>>         print('try to print X position')
>>>         print(position[0])
>>>
>>> #-------------------------------------------------------------------
>>> import pyqtgraph as pg
>>>
>>> app = pg.mkQApp("Examples")
>>> win = pg.GraphicsLayoutWidget(show=True, size=(800,800), border=True)
>>> win.setWindowTitle('ROI Example')
>>>
>>> plot = win.addPlot()
>>> plot.setXRange(0,10)
>>> plot.setYRange(0,10)
>>>
>>> roi=pg.PolyLineROI([[5.0,2], [6.0, 2], [6.0, 5]], pen=(6,9),
>>> closed=False)
>>> plot.addItem(roi)
>>>
>>> roi.sigRegionChangeFinished.connect(lambda roi: roi_changed(roi))
>>>
>>> print('Print Handles position as they are created')
>>> Handles=roi.getLocalHandlePositions() # Get list of handles
>>> for h in Handles: # Print handles position
>>>     position=h[1]
>>>     print(position)
>>>
>>> print('... Then when I move one handle...')
>>>
>>> pg.exec()
>>>
>>> Initially the code will print the positions of the three handles as
>>> following
>>> Point(5.000000, 2.000000)
>>> Point(6.000000, 2.000000)
>>> Point(6.000000, 5.000000)
>>>
>>> but when I move one of the handles, so that the "roi_changed" function
>>> is activated by the event, the handle that I move changes its "nature" and
>>> when I print its position I get:
>>> PyQt5.QtCore.QPointF(6.5, 2.9)
>>> instead of
>>> Point(6.5, 2.9)
>>>
>>> the problem is that I want to extract the X position and while the
>>> position=Point(5,2) is subscriptable, so that position[0]=5
>>> I cannot do the same to extract X position from PyQt5.QtCore.QPointF
>>>
>>> In fact you will see that my code fails
>>>
>>> I hope you can help to find a way to extract X position in all the cases
>>>
>>> thanks
>>> Salvatore
>>>
>>>
>>> --
>>> 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/e44e0745-8a65-40f1-b6bb-953234d097d8n%40googlegroups.com
>>> <https://groups.google.com/d/msgid/pyqtgraph/e44e0745-8a65-40f1-b6bb-953234d097d8n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> 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/7ace7c12-7186-42ee-b090-42472b9a7234n%40googlegroups.com
> <https://groups.google.com/d/msgid/pyqtgraph/7ace7c12-7186-42ee-b090-42472b9a7234n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CA%2BnduTHjo%3Ds1c2ztRm7o5dLRszStNzGN_tyB1x8-3-nJ9k4Vkg%40mail.gmail.com.

Reply via email to