0

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.

dr.umma
  • 37
  • 4
  • It is emitting both line and point hover signals for me. But the signals stretch beyond the border for me as well. What is the problem you are having? – Alexander Jun 16 '22 at 01:06
  • Thanks for trying it out! For me it only emits point hover signals. I get line hover signals only beyond the chart borders. Are you also using pyside6? Btw. I am working on Linux, not sure whether it makes a difference – dr.umma Jun 16 '22 at 08:06
  • I was working on windows but I just fired up my ubuntu pc and it shows the line hover on it too. I am using PySide6 – Alexander Jun 16 '22 at 08:21
  • The signals beyond the edges is much worse on ubuntu though. – Alexander Jun 16 '22 at 08:23
  • I can configrm that it works on Win. It seems to be an issue only on ubuntu – dr.umma Jun 16 '22 at 08:58
  • Opened a bug ticket for pyside https://bugreports.qt.io/browse/PYSIDE-1971. – dr.umma Jun 16 '22 at 10:08

0 Answers0