PDA

View Full Version : Image Zoom in/out



Vivek1982
22nd November 2013, 11:41
Dear All,

I need to zoom the image, which is set in the QLabel with QPixmap. Here my label size is fixed (350,450). In this i have loaded pixmap image.png which is of size 900*732. I have scaled the content while in the Ui form. Now I need to Zoom-in/out the image inside the QLabel. Plz sugest me.

Vivek1982
22nd November 2013, 18:04
Hi to all...wat may be solution for this whether keeping scaled content in ui form is wrong or wat... Basically I need to know how zoom process is done on image which is loaded on q label

saman_artorious
22nd November 2013, 19:54
Hi to all...wat may be solution for this whether keeping scaled content in ui form is wrong or wat... Basically I need to know how zoom process is done on image which is loaded on q label

use QPixamp::scaled to fit the pixmap to the relevant widget. Find what happens if you give sizes outside the range of the widget. It may also be good that you take a look at Qt Image Viewer example.

stampede
22nd November 2013, 20:01
Label is just a simple display widget, it doesn't have any image processing capabilities or view abstraction, so you have to do all the math yourself (there is nothing like QLabel::setZoom or QPixmap::setZoom). You can save the original image, select the area of the image via QPixmap::copy method and set it as the new label's pixmap. On each zoom change.
Alternative is to use QGraphicsView, add the image to scene, and then use transformation matrix to manipulate the scaling effect (m11() and m22() for horizontal / vertical scaling factors respectively), or "QGraphicsView::scale" method. More efficient and easier to implement.

Another option if you want to stick to QLabel is to subclass it, reimplement paintEvent and implement zoom by proper combinations of QPainter transformations (translate / scale).