I have created a QGraphicsView and inside it a QGraphicsScene. I load a pixmap in the QGraphicsScene. Actually it's an inherited QGraphicsScene which implements a wheelEvent in order to make the zoom in/out function. Zoom function scales the pixmap by 10% up or down depending on the wheel's rotation. The scaling works fine, however the QGraphicsView size or QGraphicsScene size gets the value of maximum size of the rotation that was tried and not center any more. For example, If I scale it up using the wso that the scroll bars enabled then if I scale it down the scroll bars still are enabled and the pixmap goes at the top-left corner. Any suggestions?
Edit: The scale function of QGraphicsView creates a low quality pixmap, that's why I don't use it. I'm adding a scaled pixmap and at every rotation I scale it again and project to GraphicsView. However the the size of GraphicsView or QGraphicsScene has resizing problems as mentioned before.
After a long time I found the solution to that. The problem was that the scene didn't follow the size of the pixmap. For example, when I was scrolling and created a large pixmap so that scroll bars were needed then if I was scrolling and created a small pixmap the scroll bars were still there cause the size of scene didn't change. However I found the solution to that by setting a rect in scene after adding the new pixmap. So Inside the wheelEvent (self, event)
function, after clearing the scene by self.clear()
and adding the new scaled pixmap, the size of scene need to change too. To do that I used the below command where self.__size
is the new size of the scaled pixmap.
self.setSceneRect(QtCore.QRectF(0.0, 0.0, self.__size.width(), self.__size.height()))