Raj*_*war 10 c++ qt point mouseover qcustomplot
我试图QCustomPlot在我的线条样式中显示不同点的绘图值lsLine.我知道我可以设置一个鼠标悬停在信号上QCustomPlot但不会真正有用,因为我只需要在鼠标悬停在绘制的线上时得到通知.我的问题是有没有办法找出鼠标是否在我的散点上.是否有可以连接的信号,当鼠标在散点上时会告诉我?
Nej*_*jat 10
您可以轻松地将插槽连接到发出的mouseMove信号QCustomPlot.然后,您可以使用它QCPAxis::pixelToCoord来查找坐标:
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));
}
Run Code Online (Sandbox Code Playgroud)
重新实现QCustomPlot::mouseMoveEvent或连接到QCustomPlot::mouseMove.
然后使用极轴coordToPixel翻译(光标)像素COORDS绘制COORDS并在搜索最近点QCPDataMap用QMap::lowerBound(cursorX).