Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Example of Zooming QPixmap Within a Frame
kendavistoo last edited by
I have written an example which should be useful. An jpg image is loaded from a resource file. It is converted to a pixmap. QPainter is used to draw a viewport of the image in a QFrame. The mouse wheel is used to vary the size of the viewport rectangle. This zooms the image in the frame. The pixmap can moved under the viewport by dragging with the wheel button (Qt::MidButton).
A second frame displays the entire image, and the viewport is represented in this second frame by an overlying red rectangle. This rectangle can be translated with the WASD keys or the arrow keys. The red rectangle can be dragged with the wheel button.
Signals and slots are used to communicate between the two frames. My coding usually is kind of clunky. For example, I call update() within paintEvent() to create a loop - this probably is not a good idea. The project is available on GitHub as Qt-Image_Zoom_Example at https://github.com/kendavistoo. I hope this helps somebody.