PDA

View Full Version : How to achieve showAll ?



Gopala Krishna
11th May 2007, 20:40
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()
{
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 );
}
}

But somehow this method doesn't show all items. Some items are half shown . Can anyone help me ?

wysota
11th May 2007, 21:38
fitInView(scene()->itemsBoundingRect(), Qt::KeepAspectRatio);

Gopala Krishna
12th May 2007, 18:06
fitInView(scene()->itemsBoundingRect(), Qt::KeepAspectRatio);

Thanks for the answer. But scene()->itemsBoundingRect() does the same thing I'm doing now (OR'ing sceneBoundingRects). Unfortunately I still experience above said problems. :confused:

Gopala Krishna
12th May 2007, 18:18
Problem solved!!! :p

The problem was with the size of scene rect. The scene rect was smaller than the viewport rect. After setting this right, it works without any problem. :)

sincnarf
5th October 2007, 14:12
what exactly did you do? you made the scene size equal or greater than the view size?

marcel
5th October 2007, 14:26
Equal. Setting it larger will cause the view to add scrollbars.