GraphicsView doesn't center on the contents upone setting the scene



  • My program behaves visually very similar to that 40.000 chips example program found in the qt creator: It creates many rectangle QGraphicItems, adds them to a scene and sets the scene to my QGraphicsview subclass. It used to set the scene so that the contents were centered, but after some feature it started placing the graphicsView at the top left corner of the contents.
    The real problem is that if the user tries to zoom out before he did any scrolling the view jumps to the center of the contents and then does the zooming, which is confusing to a user because seemingly all the changes to the tiles he did (one in the top left corner) seemingly vanish until they notice that the view has jumped towards the middle of the contents.

    Is there something I'm forgetting to set upon initializing the graphicsview so that it doesn't start centered?



  • Found it. This behavior is somehow controlled by the resizeAnchor property. It appears that when the GraphicsView is placed in the program through the UI designer the property in question is set to noAnchor. Setting it to either AnchorUnderMouse or AnchorViewCenter completely fixes the problem.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.