3

フラグが設定され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);

しかし、何かがおかしいです。バウンディングボックスが小さく、アイテムの右側に表示されます...

4

1 に答える 1

4

ちょうどそれを理解した、QGraphicsView :: viewportTransform()ドキュメントは「ビューポート座標をシーン座標にマップするマトリックスを返します」と言いますが、実際にはシーンビューポート変換に返します。

最後のステップでvp_transを反転すると、問題が修正されました。

于 2009-11-12T14:17:40.543 に答える