Fix GraphicsScene.itemsNearEvent and setClickRadius#2383
Fix GraphicsScene.itemsNearEvent and setClickRadius#2383j9ac9k merged 2 commits intopyqtgraph:masterfrom
Conversation
* Correctly consider the click radius when mapping position to items * Remove workaround for InfiniteLine * Adjust test
|
Hi @bbc131 Thanks for the PR and thanks for tackling this issue. Looks like something in the code diff might be triggering some kind of race condition that some of the tests are failing, it's been a while since I've seen this kind of random assortment of OS/bindings/python-versions failing... I haven't run the test suite locally, have you been able to replicate any kind of test failure on your system? |
I cannot reproduce this behaviour. |
|
Looks like all the windows jobs are passing; I'll try and spend some time today attempting to reproduce this on macOS. |
|
Follow up, I can reproduce the issue on macOS with pyqt5 5.15.7 and python 3.9 (likely can on other environments too). I'll work on debugging this a bit since you can't reproduce @bbc131 |
| px = pg.Point(-0.5, -1.0 / 3**0.5) | ||
| assert br.containsPoint(pos + 5 * px, QtCore.Qt.FillRule.OddEvenFill) | ||
| assert not br.containsPoint(pos + 7 * px, QtCore.Qt.FillRule.OddEvenFill) | ||
| assert br.containsPoint(pos + 2 * px, QtCore.Qt.FillRule.OddEvenFill) |
There was a problem hiding this comment.
When I change the 2 to a 1, this check passes on my machine; not sure if that is the appropriate test tho.
|
Regarding the test case which fails here at the 3rd assert: I think, that my choice of the values 2 and 3 is not correct, but I do not understand this testcase. The values before (5 and 7) made also no sense to me, so I chose this values by trial and error. |
|
I'm inclined to merge this, I'd like @ixjlyons to give a sanity check as he has worked w/ weird boundingRect issues of InfiniteLine before. |
|
This looks good to me. I'm not really alarmed by the |
* Fix GraphicsScene.itemsNearEvent and setClickRadius * Correctly consider the click radius when mapping position to items * Remove workaround for InfiniteLine * Adjust test * Try to fix test_InfiniteLine
There is an issue with the mapping of mouse cursor position to the items which shall get mouse events.
It's about the case, when the cursor position is not directly intersecting with the item, but is quite near to it.
For the
InfiniteLinethere exists some code, solving this, which I would say is rather a workaround. But actually, this should and can be solved withinGraphicsScene.itemsNearEvent().See also
GraphicsScene.setClickRadius(), which doesn't have any effect currently.MWE with description of resulting problems
If you run the mwe, the blue
region1should have a width of around 10 pixel and the redregion2should appear with a width of 1 pixel. This works for me with the default window size and zoom.In this case I see the following two problems:
Moving the blue
region1via mouse dragging is impossible, because it's too small. Either the left or the right line gets hovered (and dragged if clicked), but never the area in between. But, I would say this should be possible for an area which is roughly 6 px wide.Moving the red
region2via mouse dragging is impossible neither works the hovering.Reason
GraphicsScene.itemsNearEvent()returns only the items which directly intersect with the position of the event, e.g. the mouse cursor position in this case. See also the docstring, which describes the desired behaviour in my opinion.Usually, this problem isn't observed, since for the
InfiniteLine, there exists a workaround, which simply makes the bounding rect a 4 px wide line, see InfiniteLine.py line 304 and 310 (https://github.com/pyqtgraph/pyqtgraph/blob/8be2d6a88edc1e26b1f6f85c47a72c400db9a28b/pyqtgraph/graphicsItems/InfiniteLine.py#L304,L310).Resolution
In the present PR, I removed the workaround in InfiniteLine.py and reworked
GraphicsScene.itemsNearEvent()and reactivated commented code, such that the click radius is considered and the behaviour is as described in the docstring.