通过X轴坐标获取对应QPainterPath上的点
效果
源码
QPainterPath PainterPathStroker(const QPainterPath &path)
{
QPainterPathStroker ps;
ps.setWidth(0.01);
ps.setCapStyle(Qt::SquareCap);
return ps.createStroke(path);
}
QPointF PainterPathIntersect(const QPainterPath &path, double x)
{
auto rect = path.boundingRect();
QPainterPath line;
line.addRect(x - 0.005, rect.top() - 10, 0.01, rect.height() + 20);
QPainterPath ppt = path.intersected(line);
QPointF p = (ppt.boundingRect().bottomLeft() + ppt.boundingRect().bottomRight()) / 2;
return p;
}
使用
QPainterPath psPath = PainterPathStroker(details_path);
for (double i = 0; i < 100; ++i)
QPointF point = PainterPathIntersect(psPath, 100);