How to make a crosshair overlay

broken image
broken image

Y1 = QtCore.QPointF(sp.x(), area.top() + pen.width() / 2) X2 = QtCore.QPointF(area.right() - pen.width() / 2, sp.y()) X1 = QtCore.QPointF(area.left() + pen.width() / 2, sp.y()) Sp = self.chart().mapToPosition(self._value_pos) If self.chart() is None or self._value_pos.isNull(): Self.adjust_axes(math.floor(value1), math.ceil(value2))Ī possible solution is to override the drawForeground method of QChartView where the lines should be drawn based on the mouse position: class ChartView(QtChart.QChartView): Self._chart.axisX(self._line_serie).setRange(value_min, onAxisSliderMoved(self, value): If value_min >= 0 and value_max >= 0 and value_max value_min: Self.onAxisSliderMoved(())ĭef adjust_axes(self, value_min, value_max): Self._chart.addAxis(axisX, Qt.AlignBottom) Self._line_serie.append(QtCore.QPointF(i, mas)) Lay = QtWidgets.QVBoxLayout(central_widget)įor w in (self._chart_view, self.scrollbar): Mas =ĭef _init_(self, start = 1, parent=None): from PyQt5 import QtCore, QtGui, QtWidgets, QtChart Сan use this code as a basis to add a crosshair. I want to use the button to add and remove the crosshair.

broken image

There are few examples on the Internet on this topic. The crosshair should move behind the mouse. I need to add a crosshair, like here on the page.

broken image