increase scenerect with add item in qgraphicsview
hi friends,experts,
im having a scene where items will be added continuously and out of specific sceneRect. items can be added infinite .
ex: if i set the scene rect as (0, 0, 5000, 5000) there is a chance that an item can be added say pos (5010, 5010) so i cant able to define the scene rect .
im implementing panning on graphicsview . so i need the scene rect to restrict within the items added . the item can be increased and the scene rect has to increase proposition to it. if i set 32000x32000 even if no items has been added. it wil lshow lots of empty spaces
i cant use scene->setSceneRect(scene->itemsBoundingRect()); because initially there wont be any item and i have to drop the item to scene rect.
so i need to specify initilaly some sceneRect like viewport->rect() of graphicsview. then i have to increase it when ever any items added .
so how i can increase the sceneRect when the items keep on adding and the view increases its scroll area.
thanks in advance.
Re: increase scenerect with add item in qgraphicsview
Any specific reason for setting the scene rect?
Re: increase scenerect with add item in qgraphicsview
Quote:
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
Code:
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());
but i dont think it is a correct way .
thanks
Re: increase scenerect with add item in qgraphicsview
Don't set the scene rect at all, it should work by itself. Just keep adding the items.