Skip to content
Advertisement

Hover Tool for plots in Pyqtgraph

I want to have data information shown when hovering over a line in pyqtgraph plots, but can’t get my sigpointsHovered to emit any signal. Here is a simple example of what i tried to do:

JavaScript

I have already tried setting "hoverable" = True and read the docs several times, but I honestly have no clue why the sigPointsHovered is not working.

Advertisement

Answer

Why sigPointsHovered is not working

In short: There is no way to set “hoverable” argument for PlotDataItem class’s ScatterPlotItem right now. Therefore, it is not possible to use sigPointsHovered.

You could see this in the source code of PlotDataItem class’s function updateItems.

enter image description here

Workarounds

  1. If you really want something like sigPointsHovered right now, instead of using a PlotWiget, use a ScatterPlotItem and set hoverable = True when you initialize it or when you use setData function. Run python -m pyqtgraph.examples and find the scatter plot example to see some example codes.

  2. However, from your description, I think you actually want to do something when you hover over a “cruve” (instead of points). Currently, PlotCurveItem doesn’t implement a hoverEvent, so you may try to make a class that inherits the PlotCurveItem and add a hoverEvent to it.

Let me show you how to do this.

In this example, when the cursor enters the curve, the color changes to blue, and turn back to white when it leave the curve.

JavaScript

Edit

Need to setAcceptHoverEvent to Ture

Also, in the updated example, when the cursor enters the curve, the color changes to blue, and turn back to white when it leave the curve.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement