for (int i = 0; i < agvs.size(); i++) { // 将行驶轨迹画在界面上 QPainterPath path; for (int j = 0; j < paths[i].size(); j++) { if (j == 0) { path.moveTo(paths[i][j]->x * 25 + 200, paths[i][j]->y * 25 + 50); } else { path.lineTo(paths[i][j]->x * 25 + 200, paths[i][j]->y * 25 + 50); } } painter.setPen(QPen(Qt::red, 3)); painter.drawPath(path); //根據小車的狀態畫agv if (agvs[i].getLoad()){ painter.drawPixmap(agvs[i].getCurrentX()*25+200-(nodeSpacing-nodeSize)/2,(agvs[i].getCurrentY()+1)*25+50-(nodeSpacing-nodeSize)/2,25,25,QPixmap(":/new/prefix1/agvload.png").scaled(25,25)); } else { painter.drawPixmap(agvs[i].getCurrentX()*25+200-(nodeSpacing-nodeSize)/2,(agvs[i].getCurrentY()+1)*25+50-(nodeSpacing-nodeSize)/2,25,25,QPixmap(":/new/prefix1/agv1.png").scaled(25,25)); }} },添加代碼,只有當path不爲空的時候,才華路綫
时间: 2023-11-27 12:51:42 浏览: 62
agvs仓储机器人检测数据集VOC+YOLO格式967张3类别.7z
你可以在代码中添加一个判断语句,只有当path不为空的时候才画路线,修改后的代码如下:
```c++
for (int i = 0; i < agvs.size(); i++) {
// 将行驶轨迹画在界面上
QPainterPath path;
for (int j = 0; j < paths[i].size(); j++) {
if (j == 0) {
path.moveTo(paths[i][j]->x * 25 + 200, paths[i][j]->y * 25 + 50);
} else {
path.lineTo(paths[i][j]->x * 25 + 200, paths[i][j]->y * 25 + 50);
}
}
// 只有当path不为空的时候才画路线
if (!path.isEmpty()) {
painter.setPen(QPen(Qt::red, 3));
painter.drawPath(path);
}
// 根据小车的状态画agv
if (agvs[i].getLoad()){
painter.drawPixmap(agvs[i].getCurrentX()*25+200-(nodeSpacing-nodeSize)/2,(agvs[i].getCurrentY()+1)*25+50-(nodeSpacing-nodeSize)/2,25,25,QPixmap(":/new/prefix1/agvload.png").scaled(25,25));
} else {
painter.drawPixmap(agvs[i].getCurrentX()*25+200-(nodeSpacing-nodeSize)/2,(agvs[i].getCurrentY()+1)*25+50-(nodeSpacing-nodeSize)/2,25,25,QPixmap(":/new/prefix1/agv1.png").scaled(25,25));
}
}
```
阅读全文