Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display the plot values on mouse over. - Detect Scatter points

I am attempting to display the plot values of different points on my QCustomPlot in which I have a Line style of lsLine. I know i could set a mouse over signal on the QCustomPlot but that wont really help since I just need to be informed when the mouse is over my plotted line.My question is is there any way to find out if the mouse is over my scatter point. Is there a signal i could connect to that would tell me when the mouse is over a scatter point ?

like image 883
Rajeshwar Avatar asked Aug 09 '13 05:08

Rajeshwar


2 Answers

You can easily just connect a slot to the mouseMove signal that QCustomPlot emits. You can then use QCPAxis::pixelToCoord to find the coordinate :

connect(this, SIGNAL(mouseMove(QMouseEvent*)), this,SLOT(showPointToolTip(QMouseEvent*)));

void QCustomPlot::showPointToolTip(QMouseEvent *event)
{

    int x = this->xAxis->pixelToCoord(event->pos().x());
    int y = this->yAxis->pixelToCoord(event->pos().y());

    setToolTip(QString("%1 , %2").arg(x).arg(y));

}
like image 177
Nejat Avatar answered Sep 22 '22 15:09

Nejat


Reimplement QCustomPlot::mouseMoveEvent or connect to QCustomPlot::mouseMove.

Then use axes' coordToPixel to translate (cursor) pixel coords to plot coords and search nearest points in your QCPDataMap with QMap::lowerBound(cursorX).

like image 32
Obey-Kun Avatar answered Sep 21 '22 15:09

Obey-Kun