我需要获取设置了标志的QGraphicsItem
s的边界框(在场景空间中)。QGraphicsItem::ItemIgnoresTransformations
根据文档,您需要使用QGraphicsItem::deviceTransform()来做到这一点。我试过这个:
// Get the viewport => scene transform
vp_trans = view.viewportTransform();
// Get the item => viewport transform
trans = item.deviceTransform(vp_trans);
// Get the item's bounding box in item's space
bbox = item.boundingRect();
// Map it to viewport space
bbox = trans.mapRect(bbox);
// Map it back to scene's space
bbox = vp_trans.mapRect(bbox);
但是出了点问题,边界框看起来更小,并且在项目的右侧很远......