Important: Please read the Qt Code of Conduct -

QGraphicsView scale Scene to only visible elements

  • I have a QGraphicsScene with some elements in it.

    I want the QGraphicsView scale to the content of QGraphicScene.

    This works well with:


    Now in the QGraphicsScene some of its elements are not visible with


    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 pass mGraphicsView->scene()->sceneRect() as the rectangle for fitInView(), 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.

Log in to reply