简体   繁体   中英

qt convert mouse position to chart coordinate system

I would like to display a callout on a QChart with a QBarSeries displayed. I'm struggling in how to convert the position of my mouse to the qchart coordinate frame, so that I can use it as Anchor in my callout. I would like to set it during my

MainWindow::barSeriesHovered(bool status, int index, QBarSet *barset){}

event.

I managed to do it using following code:

auto point = QCursor::pos();
point = myChartView->mapFromGlobal(point);
auto pointF = myChartView->mapToScene(point);
pointF = myChartView->chart()->mapFromScene(point);
pointF = myChartView->chart()->mapToValue(point,myChartView->chart()->series().at(0));
myCallout->setAnchor(pointF);

maybe not the most efficient use, but yes, it works Another drawback is, that it always appears at the border of a bar, and does not move with your mouse cursor while you move around inside the bar, but yes, it works

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM