Hello, thanks for your kind reply and sorry if I replied to you after so much time. In the end I figured out what was causing the issue. In substance, when I set the position of the two lines, I wasn't considering that the position of the objects aren't absolute but are relative to their origin points. So when I was setting the new position of the second line, in reality I was changing the origin point of that line. So because pyqtgraph calculates the position of objects as sum of their origin point and the distance from it (delta), the object delta was added to the position I was trying to set and this caused the line to be drawn in a different position than the one I was expecting. I hope this explaination is clear enough to help someone who is facing this issue. Anyway, thanks very much for your help.
Il giorno mercoledì 26 maggio 2021 alle 18:19:13 UTC+2 [email protected] ha scritto: > Hi Andrea, > > I have a little time before I start my work-day, but at a glance, I > suspect what the issue here is a difference between painter coordinates and > a difference between viewbox coordinates, which don't match up. > > For your distance object, I would highly recommend you inherit from > TextItem > <https://pyqtgraph.readthedocs.io/en/latest/graphicsItems/textitem.html>, > it offers anchor/position capability, and the text size will remain the > same regardless of the zoom level, which appears to be a good chunk of the > code that you're trying to manage there. You can add just the little bits > you need > > The example you're trying to work with feels *really* close to the > InfiniteLine.py > example > <https://github.com/pyqtgraph/pyqtgraph/blob/master/examples/InfiniteLine.py>'s > > usage of pg.TargetItem > <https://github.com/pyqtgraph/pyqtgraph/blob/master/pyqtgraph/graphicsItems/TargetItem.py> > (docs for TargetItem > <https://pyqtgraph.readthedocs.io/en/latest/graphicsItems/targetitem.html>) > (in the examples, the target is a symbol, but it supports drawing any > QPainterPath object, and maybe the line underneath the text readout can > just be a QPainterPath object that just represents 1 line. > > Sorry I can't be more specific with where the bug is, but debugging a 500 > line python file before my work starts isn't always feasible. Oh, and > lastly I would suggest not setting `useOpenGL` while getting the initial > version working. While OpenGL can add significant performance boosts, > there are a number of bugs (in our library, Qt and the openGL > implementations on each OS) that could cause confusion. Best get a > non-openGL version working first and go from there. > > Sorry I can't be more specific. > > > > On Wed, May 26, 2021 at 07:50 Andrea Manghi <[email protected]> wrote: > >> >> Hello, >> I'm trying to make a little project with PyQtGraph. >> Briefly, my goal is to draw a sort of ruler that measures the distance >> between three points. >> One point is the origin of the measure, and the other two are independent >> points. >> Something like this: >> [image: Screenshot (36).png] >> I've tried everything and the best result I managed to obtain is this. >> The problem I'm facing is that when I put one line on the common point >> and the other under it, like this: >> [image: Immagine 2021-05-26 162818.png] >> If I click one of the two lines, the design brokes, and I can't >> understand why this happens and how to prevent it. >> [image: Immagine 2021-05-26 162846.png] >> I'd like to understand more precisely how PyQtGraph handles the drawing >> of the objects because at the moment I can't comprehend how I could change >> my code to make it work as I want. >> >> -- >> 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/43e59f9c-5faf-46d5-8684-8b7e53d3d6f1n%40googlegroups.com >> >> <https://groups.google.com/d/msgid/pyqtgraph/43e59f9c-5faf-46d5-8684-8b7e53d3d6f1n%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/a6a9f23f-2dcf-46d4-92d5-7288009bd467n%40googlegroups.com.
