if (i < paths.size() && !paths[i].empty() ) { for (int j = 0; j < paths[i].size() - 1; j++) { if (paths[i][j] && paths[i][j + 1]) { painter.setPen(QPen(Qt::red, 2)); QPoint start(paths[i][j]->x * 25 + 200 +nodeSize/2, (paths[i][j]->y+1 )* 25 + 50 +nodeSize/2); QPoint end(paths[i][j + 1]->x * 25 + 200 +nodeSize/2, (paths[i][j + 1]->y+1)* 25 + 50 +nodeSize/2); painter.drawLine(start, end); } } },添加代碼:以小車當前的坐標,和小車下一個坐標畫出一個矩形
时间: 2024-03-08 17:50:08 浏览: 49
install.rar
可以在代码中添加以下内容来实现以小车当前坐标和下一个坐标画出一个矩形的功能:
```c++
if (i < paths.size() && !paths[i].empty() ) {
for (int j = 0; j < paths[i].size() - 1; j++) {
if (paths[i][j] && paths[i][j + 1]) {
painter.setPen(QPen(Qt::red, 2));
QPoint start(paths[i][j]->x * 25 + 200 + nodeSize/2, (paths[i][j]->y+1) * 25 + 50 + nodeSize/2);
QPoint end(paths[i][j + 1]->x * 25 + 200 + nodeSize/2, (paths[i][j + 1]->y+1) * 25 + 50 + nodeSize/2);
painter.drawLine(start, end);
// 添加以下代码
QRect rect(end.x() - nodeSize/2, end.y() - nodeSize/2, nodeSize, nodeSize);
painter.drawRect(rect);
}
}
}
```
这样就可以在画出路径的同时,以小车当前坐标和下一个坐标画出一个矩形。
阅读全文