I'm doing an app based completely on GraphicsView. I need to implement a feature - showAll which on enabling should scale view such that all items are visible (criteria being scale factor should be as high as possible).
My initial approach is this
void SchematicView::showAll()
{
QList<QGraphicsItem*> _items = items();
if ( !_items.isEmpty() ) {
intersect = _items.first()->sceneBoundingRect();
intersect |= it->sceneBoundingRect();
}
intersect.adjust( -10, -10, 10, 10);
fitInView( intersect, Qt::KeepAspectRatio );
}
}
void SchematicView::showAll()
{
QRectF intersect;
QList<QGraphicsItem*> _items = items();
if ( !_items.isEmpty() ) {
intersect = _items.first()->sceneBoundingRect();
foreach( QGraphicsItem* it, _items ) {
intersect |= it->sceneBoundingRect();
}
intersect.adjust( -10, -10, 10, 10);
fitInView( intersect, Qt::KeepAspectRatio );
}
}
To copy to clipboard, switch view to plain text mode
But somehow this method doesn't show all items. Some items are half shown . Can anyone help me ?
Bookmarks