
Originally Posted by
Santosh Reddy
Any specific reason for setting the scene rect?
thanks for the reply
Panning and zooming .
the items can be added one after another like a tree view .
so some branch item can be shown away from the viewport.contentsRect()
in that case i have to pan the view . like http://www.qtcentre.org/wiki/index.p...ng_and_Zooming
but in that example the scene rect is defined which is not in my case.
my current implementation is
when an item is added
QRectF viewRect
= view
->contentsRect
();
QRectF itemsBounds
= this
->itemsBoundingRect
();
if(itemsBounds.width() >= sceneRect().width())
{
this->setSceneRect(itemsBoundingRect());
}else
this->setSceneRect(view->contentsRect());
if(itemsBounds.height() >= sceneRect().height())
{
this->setSceneRect(itemsBoundingRect());
}else
this->setSceneRect(view->contentsRect());
QGraphicsView *view = this->views().at(0);
QRectF viewRect = view->contentsRect();
QRectF itemsBounds = this->itemsBoundingRect();
if(itemsBounds.width() >= sceneRect().width())
{
this->setSceneRect(itemsBoundingRect());
}else
this->setSceneRect(view->contentsRect());
if(itemsBounds.height() >= sceneRect().height())
{
this->setSceneRect(itemsBoundingRect());
}else
this->setSceneRect(view->contentsRect());
To copy to clipboard, switch view to plain text mode
but i dont think it is a correct way .
thanks
Bookmarks