2009-11-12 31 views
1

我需要获取设置了QGraphicsItem::ItemIgnoresTransformations标志的QGraphicsItem的边界框(在场景空间中)。在Qt图形视图中获取恒定大小项目的边界框

根据文档,您需要使用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); 

可是,我错了,边框看起来更小和远来的物品的权利......

回答

2

就想通了,的QGraphicsView :: viewportTransform()医生说“ 返回一个矩阵,将视口坐标映射到场景坐标“,但实际上它将返回场景视口变换。

在最后一步反转vp_trans解决了我的问题。

+0

我遇到了和你一样的问题,并解决了这个问题。非常感谢! – 2016-03-16 20:12:50

相关问题