Proper resetting the transformation
-
In my simple image viewer the image can be panned/zoomed and also fitted to the available width/height. I am facing the problem with fitting the image to the available height (by pressing H key). It works initially, but once the image is zoomed/panned, the image is not centered when fitted any more. While I perform resetting the transformations of both the QGraphicsView and QtWidgets.QGraphicsPixmapItem(), this operation seems to be insufficient.
The full code is here https://github.com/drifted-in/jet-browser-qt-for-python/blob/main/jetbrowser.py
Any clue what is missing in my code? -
@jan-tosovsky after resize event, the image position has to be adjusted for center alignment. Otherwise, its position will not change.
-
@JoeCFD Thanks, it works nicely with a small tweak (scaling the image width):
x = (graphics_view.width() - scale * image_rect.width()) * 0.5However, it still unclear why resetting the transform doesn't reset the viewport to the initial state when it works without this extra translation.
-
@jan-tosovsky after resize event, the image position has to be adjusted for center alignment. Otherwise, its position will not change.