I have a problem with scaling an image in QT. I have a GraphicsView that has an image displayed and I have put in a slider to be able to allow the user to zoom in and out. For this, I've been using the scale function of the QTransform class to achieve this. It generally works if I zoom in, ie, if value gets bigger and bigger. However, when I go the opposite direction (making value smaller and smaller), the entire image disappears. Zooming back in doesn't fix the problem either; the entire image is no longer present no matter how much I zoom in or out. So the following are snippets of my code.
void MainWindow::on_ZoomSlider_valueChanged(int value)
{
QTransform transformer;
transformer.scale(scaler(value),scaler(value));
ui->graphicsView->setTransform(transformer);
}
qreal MainWindow::scaler(int value)
{
if(value < 0)
return 1/(-(value-1));
else if(value >0)
return value+1;
else
return value+1;
}
I'd be happy to offer any more clarification on my problem if it'd help you help me figure out what's wrong.