Is there a way to get mouse's coordinates on plotting area of a QChartView
? Preferably in the axis units. The goal is to display mouse's coordinates while moving the mouse around on the plot so the user can measure plotted objects.
I couldn't find any built in function for this on QChartView
, so I'm trying to use QChartView::mouseMoveEvent(QMouseEvent *event)
to try and calculate the resulting position in the plotting area. The problem is I can't get any reference to the plot area's coordinate system.
I've tried using mapToScene
, mapToItem
and mapToParent
and also the reverse mapFrom...
on all objects I can grab a hold of to try to do this, but to no avail.
I've found that QChartView::chart->childItems()[2]
is indeed the plotting area, excluding the axis and axis labels. I can then call QChartView::chart->childItems()[2]->setCursor(Qt::CrossCursor)
to make a cross appear only on the plotting area and not on the adjacent objects. But still, nothing I try seems to make a correct reference to this object's coordinate system.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…