std::vector<std::vector<Node*>> paths(agvs.size()); for (int i = 0; i < agvs.size(); i++) { //畫出agv獲取path上的坐標點之間的連綫 if (i < paths.size() && paths[i].size() > 1 && paths[i][0] != nullptr) { QPainterPath path; path.moveTo(paths[i][0]->x, paths[i][0]->y); for (int k = 1; k < paths[i].size(); k++) { if (paths[i][k] != nullptr) { path.lineTo(paths[i][k]->x, paths[i][k]->y); if (painter.isActive()) { painter.setPen(QPen(Qt::red, 20)); painter.drawLine(paths[i][k-1]->x, paths[i][k-1]->y, paths[i][k]->x, paths[i][k]->y); } } } } },爲什麽沒有繪製出直綫
时间: 2023-12-21 17:03:47 浏览: 132
node-global-paths:返回节点全局路径
根据提供的代码,似乎是缺少 `painter.strokePath(path, QPen(Qt::red, 20));` 这一行代码,导致没有绘制出直线。可以尝试将以下代码:
```
if (painter.isActive()) {
painter.setPen(QPen(Qt::red, 20));
painter.drawLine(paths[i][k-1]->x, paths[i][k-1]->y, paths[i][k]->x, paths[i][k]->y);
}
```
修改为:
```
if (painter.isActive()) {
painter.setPen(QPen(Qt::red, 20));
painter.drawLine(paths[i][k-1]->x, paths[i][k-1]->y, paths[i][k]->x, paths[i][k]->y);
painter.strokePath(path, QPen(Qt::red, 20));
}
```
这样可以在绘制直线的同时,使用 `painter.strokePath()` 方法将路径绘制出来。
阅读全文