PDA

View Full Version : problem in scaling images



sara2662
11th September 2012, 11:03
Hi every one. I'm very very beginner in QT. Plz help me if u have any idea for my problem, with many thanks.
Now my problem:
In part of my project I load an image and now I want to zoom in/out it; but I can't. The image and "scaleSlider" are shown on the screen properly, but changing scale by scaleSlider does not affect the image. this is my code:

void PanelWidgets::slotChangeImage(int val)
{
image.scaled(image.width()*val/100, image.height()*val/100);
qDebug()<<val;
}

and after many lines, we have:


bool b = image.load(":res/dab/logo.jpg");
if(!b) qDebug()<<"Can not load image from path";
if(b) scene->addPixmap(QPixmap::fromImage(image));
QSlider *scaleslider = new QSlider(Qt::Horizontal,this);
scaleslider->setRange(10,1000);
scaleslider->setGeometry(700,100,200,30);
connect(scaleslider,SIGNAL(valueChanged(int)),this ,SLOT(slotChangeImage(int)),Qt::UniqueConnection);

I'm using QT Creator 2.4.1 (based on QT 4.7.4 32bit) and Win 7 x86.

Rhayader
11th September 2012, 11:49
The QImage::scaled() returns a copy of the image scaled to new size
There is also the Image Viewer Example in docs http://doc.qt.nokia.com/4.7-snapshot/widgets-imageviewer.html with zoom-in / zoom-out already implemented for studying