Narek
Narek

Reputation: 39881

Zooming the graphics in Qt

I use QGraphicsView and QGraphicsScene in order to draw graphics.
How can I organize zoom-in and zoom-out (during zooming in scrolls should appear and while zooming out scrolls should disappear)?

Upvotes: 1

Views: 5272

Answers (1)

Valentin H
Valentin H

Reputation: 7448

QGraphicsView::scale(qreal, qreal)

e.g. 
QGraphicsView * view = new QGraphicsView (parent);
QGraphicsScene *scene = new QGraphicsScene();
scene->addText("Hello World");
view->setScene(scene);
view->show();
view->resize(100,100);

// coll from some slot to see the effect
view->scale(2,2);   //zoom in
view->scale(.5,.5); //zoom out

Scroll-bars will disappear automatically if scene fits into the size of view.

Regards, Valentin

Upvotes: 5

Related Questions