Reputation: 1406
my qgraphicsscene is having qgraphicswidget which constantly adding qgraphicsLayoutItem. in graphicsView i need to get the qgraphicswidget geometry in scene coordinated. i tried QList items = scene()->items(); and check its with type
foreach (QGraphicsItem *item, items) { if(item->type() == ItemType) { }
but how to convert item to qgraphicswidget and change its gemoetry to scene coordinates. normal item.boundingRect returns constantly 0,0, 10x10
Upvotes: 0
Views: 691
Reputation: 25155
The bounding rect of the item is in item coordinates. To map it to scene coordinates, use QGraphicsItem::mapToScene():
const QRectF mapped = item->mapToScene(item->boundingRect());
To cast a QGraphicsItem, you can simply use dynamic_cast or static_cast, or the special qgraphicsitem_cast:
auto widget = qgraphicsitem_cast<QGraphicsWidget*>(item);
To map the coordinates, casting shouldn’t be necessary though.
Upvotes: 1