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 ?
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));
}
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)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With