Important: Please read the Qt Code of Conduct -

QGraphicsScene fit scene rect into current view size without changing its position

  • I am trying to fit the scene rect, into current widget size, to prevent from showing unnecessary items and scroll bars.

    Unlucky, when i change the scene rect size, the view change it's position, which change the items that are shown, and i can't figure it out how to resize the rect, without changing the view and what is displayed.

    Hiding the scrollbars doesn't help, since isVisible() (item) still return true. The performance looks like it's worse when the scene rect is big, and there are few more problems. I tried to use setSceneRect(), but i wasn't able to figure out any way, to change the size, and set the position, so it will look like it wasn't touched. I tried also sceneRect().adjust(), but still the position isn't the previous one.

    Setting a const size doesn't help, because i has to be able to pan the scene, in order to explore other items. So since pan doesn't work once the scene reach the border, i resize the scene to be able to pan to the items, then i would like to resize the scene, so the invisible items will be hidden.


  • @Loc888 QGraphicsView::fitInView?

  • @Asperamanca Doesn't work. I need to get rid of unnecessary scene size, then return the view/scene to it's LAST position, so the view will look like it wasn't changed at all, execept the size to match the current view. FitScene scale it to fit the contents, which is not what i need to do.

  • You don't really explain what you need and why. You write about "changing the scene rect", but you don't explain why you need to change the scene rect at all. You write that you want to "prevent showing unnecessary items and scrollbars", but you can hide the scroll bars, and items outside the view won't be visible to the user, so what's the problem?

Log in to reply