QGraphicsView scale Scene to only visible elements
Solved
General and Desktop
-
I have a
QGraphicsScene
with some elements in it.I want the
QGraphicsView
scale to the content ofQGraphicScene
.This works well with:
mGraphicsView->fitInView(mGraphicsView->scene()->sceneRect(), Qt::KeepAspectRatio);
Now in the
QGraphicsScene
some of its elements are not visible withsetVisible(false)
Is there a way to ignore the not visible objects and only fit to the visible ones?
-
@sandro4912
I know nothing about this(!) But you passmGraphicsView->scene()->sceneRect()
as the rectangle forfitInView()
, if you want to exclude non-visible objects can't you calculate the necessary rectangle accordingly and pass that instead? -
yeah of course i could do that. I guess I could iterate over the visible objects and calc the visible rectangle out of that. I just thought maybe Qt already has some build in method for that to not invent the wheel new.