I am working on implementing permanent tooltip functionality, i.e, display tooltip on hover and make tooltip stay permanently on clicking in my chart where I have a line series and spline series. This is basically a different version of the Qt Callout example Here's the link. The only change I have implemented is that I have used QValueAxis to add two y axes on the left side, one for each of the series. They're sharing the same x-axis. Now when I try to run the program, the tooltip appears correctly for the line curve but it is misplaced in case of spline curve. It appears at some distance perpendicularly below the point on the curve where I am hovering the mouse pointer.
This issue does not arise when I use single y axis by using createdefaultaxes().
Result with single y axis
Result with multiple y axes
I have posted the code related to the click and hover functions below. Objects of the class "Callout" are being used in this code so here's the code for Callout (same link as the one I posted before). I wasn't able to figure out which snippets of Callout code are the most relevant regarding this question and hence I had to post the link.
// chart
m_chart = new QChart;
QLineSeries *series = new QLineSeries;
//appended some (x,y) values to series and added to chart
m_chart->addSeries(series);
QSplineSeries *series2 = new QSplineSeries;
//appended some (x,y) values to series2 and added to chart
m_chart->addSeries(series2);
//m_chart->createDefaultAxes(); for single y axis
QValueAxis *axisX = new QValueAxis;
QValueAxis *axisY1 = new QValueAxis; //for multiple y axes
QValueAxis *axisY2 = new QValueAxis;
m_chart->addAxis(axisX, Qt::AlignBottom);
m_chart->addAxis(axisY1, Qt::AlignLeft);
m_chart->addAxis(axisY2, Qt::AlignLeft);
series->attachAxis(axisX);
series->attachAxis(axisY1);
series2->attachAxis(axisX);
series2->attachAxis(axisY2);
m_chart->setAcceptHoverEvents(true);
setRenderHint(QPainter::Antialiasing);
scene()->addItem(m_chart);
connect(series, &QLineSeries::clicked, this, &View::keepCallout);
connect(series, &QLineSeries::hovered, this, &View::tooltip);
connect(series2, &QSplineSeries::clicked, this, &View::keepCallout);
connect(series2, &QSplineSeries::hovered, this, &View::tooltip);
this->setMouseTracking(true);
// keepCallout() function
{
m_callouts.append(m_tooltip);//m_callouts is a QList of "Callout" class type
m_tooltip = new Callout(m_chart);
}
//tooltip(QPointF point, bool state) function
{
if (m_tooltip == 0)
m_tooltip = new Callout(m_chart);
if (state) {
m_tooltip->setText(QString("X: %1 \nY: %2").arg(point.x()).arg(point.y()));
m_tooltip->setAnchor(point);
m_tooltip->setZValue(11);
m_tooltip->updateGeometry();
m_tooltip->show();
} else {
m_tooltip->hide();
}
}