PDA

View Full Version : QGraphicsView scale function



forrestfsu
11th October 2006, 20:17
I'm currently using graphicsview to simulate zooming in/out on an image. Zooming in seems to be perfect, but when I zoom out passed the original size of the graphicsview it begins to tile the images. I only want one image to show up...not tiled. Is there any ideas on the best way about trying to solve this problem?

wysota
12th October 2006, 00:16
Hard to tell without seeing your code. Maybe you're instantiating many items instead of one?

forrestfsu
12th October 2006, 15:05
Below is basicaly what my code is for that particular part.



scene = new QGraphicsScene;
scene->setSceneRect(0, 0, 512, 640);
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
ui.graphicsView->setScene(&*scene);

void Form::scaleView(qreal scaleFactor)
{
ui.graphicsView->scale(scaleFactor, scaleFactor);
}

bool Form::eventFilter(QObject *o, QEvent *e)
{
if (0 == ui.graphicsView->viewport()){
if (e->type() == QEvent::Wheel)
{
QWheelEvent *q = dynamic_cast<QWheelEvent*>(e);
scaleView(pow((double)2, -q->delta() / 240.0));
e->accept();
return true;
}
}
}