Mouse hover problem combining QLineSeries and QScatterSeries on a QChart (PySide6)

543 views Asked by At

I am writing a small python module to visualize data on a chart using Qt (PySide6). My goal is to distinguish between mouse hovers on QLineSeries's lines and points. Since it does not seem to be possible with the current implementation, I tried to combine a QLineSeries with a QScatterSeries and manage the hover signals separately. The problem is that adding a QScatterSeries prevents any previously added series from emitting hover signals. Is this expected behavior or am I doing something wrong? Here is a minimal example to reproduce the issue

from PySide6.QtCharts import QChart, QChartView, QLineSeries, QScatterSeries
from PySide6.QtWidgets import QApplication, QMainWindow
from PySide6.QtGui import QPen, QColor


def on_line_hover():
    print("line hover")


def on_point_hover():
    print("point hover")


app = QApplication()
main_window = QMainWindow()
main_window.show()
chart = QChart()
chart_view = QChartView(chart, main_window)
main_window.setCentralWidget(chart_view)
line = QLineSeries()
line.setPen(QPen(QColor("black"), 10))
line.append(0, 0)
line.append(1, 1)
line.hovered.connect(on_line_hover)
points = QScatterSeries()
points.setPen(QPen(QColor("blue"), 10))
points.append(0.25, 0.25)
points.append(0.75, 0.75)
points.hovered.connect(on_point_hover)

chart.addSeries(line)
chart.addSeries(points)
chart.createDefaultAxes()


app.exec()

Note: In the example above for whatever reason, hovering on the QLineSeries works outside the chart where the line goes slightly out of the border, although it is clipped by the border itself.

0

There are 0 answers