PDA

View Full Version : Zoom in a QgraphicsView using pushbutton



Panagiotis
4th February 2016, 17:53
I'm building a very simple image editor on Qt creator.I have my image displayed on a QGraphicsView and i want to give the user the ability to zoom in and out by a pushbutton.

I've searched a lot and found how to zoom in and out through the mouse wheel.As i am very new to Qt i can't adjust it to the pushbutton because i don't understand everything clearly.

I' ve tried this(without understanding completely what i'm doing)but the result isn't the wanted.It zooms in only once and quite abruptly.I want a smoother zoom and as many times as i want.


void MainWindow::on_pushButton_clicked(){
QMatrix matrix;
ui->graphicsView->setTransformationAnchor(QGraphicsView::AnchorViewC enter);
matrix.scale(1.0,1.0);
ui->graphicsView->setMatrix(matrix);
ui->graphicsView->scale(1,-1);}


I would be very grateful if you guys can help!

anda_skoa
4th February 2016, 19:22
In order to zoom you need to scale by values not equal to 1.

Scaling is basically muliplying values, scaling by 1 means no change.
E.g. if you want to make things twice as large as they are now, scale by 2 in both axis.

Cheers,
_