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

Qt Code:
  1. void SchematicView::showAll()
  2. {
  3. QRectF intersect;
  4. QList<QGraphicsItem*> _items = items();
  5. if ( !_items.isEmpty() ) {
  6. intersect = _items.first()->sceneBoundingRect();
  7. foreach( QGraphicsItem* it, _items ) {
  8. intersect |= it->sceneBoundingRect();
  9. }
  10. intersect.adjust( -10, -10, 10, 10);
  11. fitInView( intersect, Qt::KeepAspectRatio );
  12. }
  13. }
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 ?