Unsolved QGraphicsItem positioning
-
Hi,
I have a
QGraphicsEllipseItem
object, which is randomly positioned, and I would like it not to go beyond theQGraphicsView
borders, which are the same of the Window.I think I should make the
QGraphicsScene
exactly the same size of theQGraphicsView
, but so far I failed to do that, and I am not sure that this is the correct way to do it.Does anyone have a suggestion how to do it? I would appreciatte any reference too.
Thanks
-
@canellas
how about passing theQGraphicsScene::sceneRect()
toQGraphicsView::fitInView()
? -
Thanks for your time!
I tried to combine the two methods, but I failed to. Would you have an example?
Thanks
-
Hi @canellas
The "extension" of the graphics scene is the combined extension of all its objects (ellipses). In the graphics view you can set the area (rect) of the graphics scene that you want it to show with:
setSceneRect(rect);
So you will have to define a rectangle in which to vary the ellipses and set the view to show this rectangle; and make the widget big enough to show the complete view, otherwise you will get scrollbars.
-Michael.
-
Thanks for your time.
That's pretty much what I am doing.
I set the
QGraphicsView
to show no scroll bars, and theQGraphicsScene
width and height to 95% of theQGraphicsView
's size. -