Skip to content

Add legend double-click and legend sample click signals.#3111

Merged
j9ac9k merged 4 commits intopyqtgraph:masterfrom
kevinanewman:legend-double-clicks-and-legend-sample-clicks
Aug 18, 2024
Merged

Add legend double-click and legend sample click signals.#3111
j9ac9k merged 4 commits intopyqtgraph:masterfrom
kevinanewman:legend-double-clicks-and-legend-sample-clicks

Conversation

@kevinanewman
Copy link
Copy Markdown
Contributor

An application may need/want to know which plot data items are visible, the sigSampleClicked signal can be used for this purpose.

An application may want to resize the legend text after a legend has been created. The sigDoubleClicked signal can be used for this.

The example Legend.py has been updated to illustrate example use cases.

Tested against PyQt6 and PySide6.

Thank you for you consideration,
Kevin

   * can be used to pop up a legend font/style dialog, for example
add legend sample click signal
   * can be used to detect which plot data items have been made visible or invisible externally
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jul 30, 2024

Thanks for the PR @kevinanewman !

I mentioned the issue with the method that I don't think we need; the other issue I have is with what the signals are carrying.

sigSampleClicked contains the sample that was clicked, but sigDoubleClicked contains the double-click event itself, which is maybe what is wanted, but I'm not sure we need to emit that event as a signal?

self.autoAnchor(self.pos() + dpos)

def mouseDoubleClickEvent(self, ev):
self.sigDoubleClicked.emit(self, ev)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should probably pass the event to the superclass.

super().mouseDoubleClickEvent(ev)
self.sigDoubleClicked.emit(self, ev)

Copy link
Copy Markdown
Contributor Author

@kevinanewman kevinanewman Jul 30, 2024

Choose a reason for hiding this comment

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

In my case I wanted the app get a notification, I'm not making a new class or subclass (or multiple layers of them since the legend is multiple objects deep in the code).

If you try out the Legend.py example I updated you'll see what I mean. I use the double click signal to pop up a dialog box to change the legend font size. Of course other style changes could be made available as well.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Aug 18, 2024

Sorry for the delay, this LGTM. Thanks for the PR @kevinanewman

@j9ac9k j9ac9k merged commit f322261 into pyqtgraph:master Aug 18, 2024
@kevinanewman kevinanewman deleted the legend-double-clicks-and-legend-sample-clicks branch October 31, 2024 19:06
@kevinanewman kevinanewman restored the legend-double-clicks-and-legend-sample-clicks branch November 4, 2024 16:29
j9ac9k pushed a commit to j9ac9k/pyqtgraph that referenced this pull request Mar 25, 2025
)

* add legend double click signal
   * can be used to pop up a legend font/style dialog, for example
add legend sample click signal
   * can be used to detect which plot data items have been made visible or invisible externally

* update Legend.py to illustrate new signal use cases

* use fully scoped enums!

* simplification
@kevinanewman kevinanewman deleted the legend-double-clicks-and-legend-sample-clicks branch February 23, 2026 18:12
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.

2 participants