I have multiple points scattered on the plot and I have implemented showPointToolTip method as described below:
connect(ui->customPlot, &QCustomPlot::mouseMove, this, &MainWindow::showPointToolTip);
void MainWindow::showPointToolTip(QMouseEvent *event)
{
//Cursor
int x_cursor = ui->customPlot->xAxis->pixelToCoord(event->pos().x());
int y_cursor = ui->customPlot->yAxis->pixelToCoord(event->pos().y());
cursor_local->Detect_cursor_at_position(ui->customPlot,x_cursor,y_cursor);
}
And my Detect_cursor_at_position method is implemented as following:
void Cursor::Detect_cursor_at_position(QCustomPlot *customPlot,int cursor_x, int cursor_y){
for (int i = 0; i < qv_x_cursor.count(); i++) {
int cursor_coords_x = round(qv_x_cursor[i]);
int cursor_coords_y = round(qv_y_cursor[i]);
if (cursor_x == cursor_coords_x) {
if (cursor_y == cursor_coords_y) {
qDebug("Cursor detected nearby = %u \n",i);
}
}
}
}
The logic of the code above is quite simple. Everytime I move the mouse on my graph, I am capturing the mouse x and mouse y position. If the mouse position matches the some point on the graph position, I want to highlight this point.
To visualize it better, see the screenshot below:
https://ibb.co/m52HN0j
When I hover my mouse over the point on the graph (yellow triangle), the logs will be printed:
qDebug("Cursor detected nearby = %u \n",i);
My question. What method shall I use to highlight specific point on the plot when hovered over it?