Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt Qcustomplot使用鼠标事件显示选定点的坐标_Qt_Mouseevent_Mouseover_Qcustomplot - Fatal编程技术网

Qt Qcustomplot使用鼠标事件显示选定点的坐标

Qt Qcustomplot使用鼠标事件显示选定点的坐标,qt,mouseevent,mouseover,qcustomplot,Qt,Mouseevent,Mouseover,Qcustomplot,我需要在自定义绘图上显示一组点(接近200)。此后,当我点击一个特定的点,它应该显示其坐标使用鼠标事件。鼠标事件应该只能显示我单击的那些点坐标,而不能显示剩余的空白区域。我尝试过使用event->pos().x()创建像素坐标系。但是没有用。在鼠标事件中我需要帮助。你的问题有点模糊,“但不使用”是什么意思?您是否收到了该活动,但该信息没有用处?或者你从来没有参加过活动?或者某个角度的值是错误的?这是你定制的QWidget绘图吗? 好吧,不管怎样,我还是试着 如果自定义绘图是QWidget: 首先

我需要在自定义绘图上显示一组点(接近200)。此后,当我点击一个特定的点,它应该显示其坐标使用鼠标事件。鼠标事件应该只能显示我单击的那些点坐标,而不能显示剩余的空白区域。我尝试过使用event->pos().x()创建像素坐标系。但是没有用。在鼠标事件中我需要帮助。

你的问题有点模糊,“但不使用”是什么意思?您是否收到了该活动,但该信息没有用处?或者你从来没有参加过活动?或者某个角度的值是错误的?这是你定制的QWidget绘图吗? 好吧,不管怎样,我还是试着

如果自定义绘图是QWidget:
首先,您需要在小部件中启用鼠标跟踪

CustomPlotWidget->setMouseTracking(true);
然后您应该将坐标存储在鼠标按下事件中,您可以通过重写事件处理程序来实现这一点

CustomPlotWidget::mousePressEvent(QMouseEvent *event)
{
   save_coords=event->pos;
}
然后在绘制小部件时,使用该坐标在那里显示一些文本,或者可以在该位置弹出一个QToolTip(这就是我所做的,它看起来非常漂亮)

根据您的意见,如果您使用自己绘制坐标的解决方案,则只需重新绘制先前绘制坐标的部分。您可以在之前绘制时存储矩形区域,然后重新绘制该区域下的所有内容,但坐标除外

CustomPlotWidget::mousePressEvent(QMouseEvent *event)
{
   ...
   save_coords=event->pos;
   update(areaWhereYouPreviouslyDrawCoordinates);
   update(areaWhereYouWantToDrawNewCoordinates);
}
CustomPlotWidget::paintEvent(QPaintEvent *event)
{
...
   if (event->rect().insersect(areaWhereYouWantToDrawNewCoordinates))
   {
        drawCoordinates();
        areaWhereYouPreviouslyDrawCoordinates=areaWhereYouWantToDrawNewCoordinates;
   }
...
}
如果使用QToolTip使用解决方案:

CustomPlotWidget::mousePressEvent(QMouseEvent *event)
{
   ...
   if (needToDrawCoordinates)
        QToolTip::showText(Where,Coordinates);
   else
        QToolTip::hideText();
}

谢谢你,巴勃罗!是的,我收到了事件。我这边的问题是,我必须从一组点中选择一个点,该特定点应显示其坐标,当我单击其他点时,以前的坐标应消失,当前选定点的坐标应显示。