How to move toghether more points and lines with PyQtGraph?

245 views
Skip to first unread message

Andrea Manghi

unread,
May 26, 2021, 10:50:08 AM5/26/21
to pyqtgraph

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:
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:
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.
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.
imageItem_html_morelines_signals.py

Ognyan Moore

unread,
May 26, 2021, 12:19:13 PM5/26/21
to pyqt...@googlegroups.com
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, 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's usage of pg.TargetItem (docs for TargetItem) (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.



--
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 pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/43e59f9c-5faf-46d5-8684-8b7e53d3d6f1n%40googlegroups.com.

Andrea Manghi

unread,
Jul 11, 2021, 10:06:13 AM7/11/21
to pyqtgraph
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.
Reply all
Reply to author
Forward
0 new messages