Thank you for your reply d_stranz!
However, with QLineSeries and QCustomPlot, I have the same issue with "hovering". That as soon as i just hover the line i get an arbitrary point. I only want to print exact data points, as in, plotted data is by sample. It doesn't make sense to plot y-value for sample 3.5 for example.
Do you have any good ideas for QCustomPlot to only make the tooltip appear when hovering an actual sample?
Best regards
DAVC
Thank you for your reply d_stranz!
However, with QLineSeries and QCustomPlot, I have the same issue with "hovering". That as soon as i just hover the line i get an arbitrary point. I only want to print exact data points, as in, plotted data is by sample. It doesn't make sense to plot y-value for sample 3.5 for example.
Do you have any good ideas for QCustomPlot to only make the tooltip appear when hovering an actual sample?
Best regards
DAVC
Added after 1 15 minutes:
Okay, so to anyone reading this with the sample problem: You want to plot large data signals and when you hover a given signal, you want a tooltip to appear with the value for an actual sample.
Do not use QScatterSeries. It is super slow. I don't know why.
Use QLineSeries.
Attach its "hovered" signal to a lambda function, like so:
connect(lineseries,
&QLineSeries
::hovered,
[=](QPointF point,
bool state
) {this
->tooltip_
(point, state, name, ali
[bandnr
]);
});
connect(lineseries, &QLineSeries::hovered, [=](QPointF point, bool state) {this->tooltip_(point, state, name, ali[bandnr]); });
To copy to clipboard, switch view to plain text mode
This allows you to capture the default parameters from &QLineSeries::hovered, and provide any other values you might want. I want the name and the data as well. My tooptip function looks like this:
void LinePlot
::tooltip_(QPointF point,
bool state,
QString name, QVector<QPointF> data
) {
if (m_tooltip == 0)
m_tooltip = new Callout(chart_);
if (state) {
auto x = data[qRound(point.x())].x();
auto y = data[qRound(point.x())].y();
m_tooltip
->setText
(name
+ "\nX: " + QString::number(x
) + " \nY: " + QString::number(y
));
m_tooltip->setAnchor(point);
m_tooltip->setZValue(11);
m_tooltip->updateGeometry();
m_tooltip->setParentItem(chart_);
m_tooltip->show();
m_tooltip->update();
}
else {
m_tooltip->hide();
}
}
void LinePlot::tooltip_(QPointF point, bool state, QString name, QVector<QPointF> data)
{
if (m_tooltip == 0)
m_tooltip = new Callout(chart_);
if (state) {
auto x = data[qRound(point.x())].x();
auto y = data[qRound(point.x())].y();
m_tooltip->setText(name + "\nX: " + QString::number(x) + " \nY: " + QString::number(y));
m_tooltip->setAnchor(point);
m_tooltip->setZValue(11);
m_tooltip->updateGeometry();
m_tooltip->setParentItem(chart_);
m_tooltip->show();
m_tooltip->update();
}
else {
m_tooltip->hide();
}
}
To copy to clipboard, switch view to plain text mode
you can see the callout class here:
https://doc.qt.io/qt-5/qtcharts-call...llout-cpp.html
This makes a tool tip appear when you hover an actual data point. It is a bit sluggish, tough, as the tooltip only disappears when you stop hovering the line and there is a timer for this. I'll see if i can remove that somehow.
I tried setting lineserie.SetPointsVisible(true) but that turns the plotting insanely slow again.
As for QCustomPlot. It is highly customizable, but when you're a rookie like me, it also becomes a bit overwhelming.
Best Regards
DAVC
Bookmarks