0

私のqgraphicssceneには、常にqgraphicsLayoutItemを追加するqgraphicswidgetがあります。graphicsView では、調整されたシーンで qgraphicswidget ジオメトリを取得する必要があります。QList items = scene()->items(); を試しました。そしてそのタイプをチェックしてください

foreach (QGraphicsItem *item, items) { if(item->type() == ItemType) { }

ただし、アイテムをqgraphicswidgetに変換し、そのジオメトリをシーン座標に変更する方法。通常の item.boundingRect は常に 0,0, 10x10 を返します

4

1 に答える 1

1

アイテムの境界矩形はアイテム座標にあります。シーン座標にマップするには、QGraphicsItem::mapToScene()を使用します:

const QRectF mapped = item->mapToScene(item->boundingRect());

QGraphicsItem をキャストするには、単に dynamic_cast または static_cast、または特別なqgraphicsitem_castを使用できます。

auto widget = qgraphicsitem_cast<QGraphicsWidget*>(item);

ただし、座標をマッピングするために、キャストは必要ありません。

于 2015-12-14T08:56:23.507 に答える