Skip to content

Update LinearRegionItem.py#3168

Merged
j9ac9k merged 1 commit intopyqtgraph:masterfrom
dingo9:dingo9-patch-1
Jan 25, 2025
Merged

Update LinearRegionItem.py#3168
j9ac9k merged 1 commit intopyqtgraph:masterfrom
dingo9:dingo9-patch-1

Conversation

@dingo9
Copy link
Copy Markdown
Contributor

@dingo9 dingo9 commented Oct 16, 2024

fix bug in Examples/InfiniteLine.py

lr = pg.LinearRegionItem(values=[70, 80])
p1.addItem(lr)
label = pg.InfLineLabel(lr.lines[1], "region 1", position=0.95, rotateAxis=(1,0), anchor=(1, 1))

if change lr.lines[1] to lr.lines[0], label moved in drag event. Don't block InfiLine Signal directly while draging event?

fix bug in Examples/InfiniteLine.py
```
lr = pg.LinearRegionItem(values=[70, 80])
p1.addItem(lr)
label = pg.InfLineLabel(lr.lines[1], "region 1", position=0.95, rotateAxis=(1,0), anchor=(1, 1))
```
if change ```lr.lines[1]``` to ```lr.lines[0]```,  label moved in drag event. Don't block InfiLine Signal directly while draging event?
@ixjlyons
Copy link
Copy Markdown
Member

Note this looks like it aims to fix #3188.

I'll say I'm not too familiar with the events handling in LinearRegionItem, so I'd like to take a bit of a closer look, but it does seem to fix the problem.

Minimal example:

import pyqtgraph as pg

pl = pg.plot([0, 1, 2, 3], [4, 5, 6, 7])

lr = pg.LinearRegionItem(values=[0, 1])
pl.addItem(lr)
pg.InfLineLabel(lr.lines[0], "l0: {value:.2f}")
pg.InfLineLabel(lr.lines[1], "l1: {value:.2f}")

pl.show()
pg.exec()

Note also without this change, the label on line 0 can move vertically, until you trigger an event by e.g. panning/zooming, after which it snaps back to the middle.

Copy link
Copy Markdown
Member

@ixjlyons ixjlyons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed things a little more carefully and I still think this looks fine. I can't quite explain why it might've been just blocking the first InfiniteLine altogether, because that definitely breaks the connection between line and label while the region is being dragged. Furthermore, I would think other (e.g. user) connections to the InfiniteLine position change signals should still work while the region is dragged. This only blocks those events from reaching back up to the region level to avoid triplet region change events.

@j9ac9k j9ac9k linked an issue Jan 25, 2025 that may be closed by this pull request
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jan 25, 2025

Thanks for the PR @dingo9 and thanks for the review @ixjlyons This LGTM, merging!

@j9ac9k j9ac9k merged commit 31ec5b5 into pyqtgraph:master Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LinearRegionItem mouseDragEvent issue

3 participants