Qt cpp 将 message PB_ARLabel { bytes id = 1;//添加的时候不需要赋值 bytes name = 2; bytes cam_guid = 3;//所属摄像机GUID 所属通道id int32 label_type = 4;//@SEE ARLabelType repeated PB_ARPosition position = 5;//原始位置(屏幕展示不需要) 1080P repeated PB_ARPosition position_on_screen =6;//屏幕位置(屏幕显示用) 1080P int32 coordinate_type = 8;//坐标类型,1 pt坐标,2 经纬度坐标 double distance = 9;//距离(标签离摄像机的距离) 配置的时候不需要管 int32 layer = 10;//标签所在层级 bool moveable = 11;//是否可移动 int32 shape = 12;//@see enumeration ARLabelShape int32 rgba = 13;//颜色,包含透明度 int32 image_text_type = 14;//展示类型,0仅文字 1 仅图标,2 图文并存 bytes icon_file_id = 15;//图标 只有通用标签 使用此值 int32 extension = 16;//延长线 int32 angle = 17;//角度0-360 int32 radius = 18;//半径 bool fixed_direction = 19;//是否固定方向 int32 subtype = 20;//如果label_type==ARLT_DEVICE,则 3 表示报警防区,5 表示门,6表示摄像机 bytes object_id = 21;//标签对应的事物ID,依据ARLabelType,如果是设备 就是设备ID,如果是电子地图就是地图ID repeated PB_ARLabelAssociatedContent associated_content = 22;//标签关联的内容 //repeated bytes label_category_code = 24;//标签所属分类code 暂不使用 } message PB_GetARLabel { bytes cam_guid = 1;//为空表示获取所有镜头的标签 } message PB_ARLabelArray { repeated PB_ARLabel label = 1; } 。将其中的名称信息显示在QTableWidget中。并将其他信息作为tooltip展示
时间: 2024-01-05 12:04:28 浏览: 69
USB上位机驱动过程中的笔记VC6+DDK_XP+DS3
首先需要使用protobuf库来解析PB_ARLabel和PB_ARLabelArray消息。可以使用类似以下代码:
```cpp
PB_ARLabelArray arLabelArray;
arLabelArray.ParseFromArray(data, size); // data为消息数据,size为数据大小
for (int i = 0; i < arLabelArray.label_size(); ++i) {
const PB_ARLabel& arLabel = arLabelArray.label(i);
// 将名称信息插入到QTableWidget中
QTableWidgetItem* nameItem = new QTableWidgetItem(QString::fromStdString(arLabel.name()));
ui->tableWidget->setItem(i, 0, nameItem);
// 设置tooltip
QString tooltip = "ID: " + QString::fromStdString(arLabel.id()) + "\n"
+ "Camera GUID: " + QString::fromStdString(arLabel.cam_guid()) + "\n"
+ "Label Type: " + QString::number(arLabel.label_type()) + "\n"
+ "Coordinate Type: " + QString::number(arLabel.coordinate_type()) + "\n"
+ "Distance: " + QString::number(arLabel.distance()) + "\n"
+ "Layer: " + QString::number(arLabel.layer()) + "\n"
+ "Moveable: " + (arLabel.moveable() ? "true" : "false") + "\n"
+ "Shape: " + QString::number(arLabel.shape()) + "\n"
+ "RGBA: " + QString::number(arLabel.rgba()) + "\n"
+ "Image Text Type: " + QString::number(arLabel.image_text_type()) + "\n"
+ "Extension: " + QString::number(arLabel.extension()) + "\n"
+ "Angle: " + QString::number(arLabel.angle()) + "\n"
+ "Radius: " + QString::number(arLabel.radius()) + "\n"
+ "Fixed Direction: " + (arLabel.fixed_direction() ? "true" : "false") + "\n"
+ "Subtype: " + QString::number(arLabel.subtype()) + "\n"
+ "Object ID: " + QString::fromStdString(arLabel.object_id()) + "\n";
for (int j = 0; j < arLabel.associated_content_size(); ++j) {
const PB_ARLabelAssociatedContent& content = arLabel.associated_content(j);
tooltip += "Associated Content " + QString::number(j) + ":\n"
+ " Type: " + QString::number(content.type()) + "\n"
+ " Content: " + QString::fromStdString(content.content()) + "\n";
}
ui->tableWidget->item(i, 0)->setToolTip(tooltip);
}
```
上述代码中,假设QTableWidget已经有足够的行数来显示所有的标签名称,且每行只有一列来显示名称。然后使用PB_ARLabel中的其他字段来生成tooltip。最后将tooltip设置到QTableWidgetItem中即可。
阅读全文