QValueAxis *axisX = new QValueAxis;
QValueAxis *axisY1 = new QValueAxis;
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);
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();
}
}
QValueAxis *axisX = new QValueAxis;
QValueAxis *axisY1 = new QValueAxis;
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();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks