How to reset the scale in QGraphicsView?
Asked Answered
J

2

5

How can I reset the scale of a Graphics View regardless of any previous scale that was applied? Using scale() multiplies the scale I give it to the previous one:

ui->graphicsView->scale(0.1, 0.1);
ui->graphicsView->scale(2, 2);
// the scale factor is (0.2,0.2) instead of (2,2)
Jewfish answered 23/8, 2016 at 12:55 Comment(0)
J
14

QGraphicsView::resetMatrix() resets the matrix, and calling it before applying the scale works:

view->scale(0.1, 0.1);
view->resetMatrix();
view->scale(2, 2);
// the scale factor is (2,2)
Jewfish answered 23/8, 2016 at 12:55 Comment(0)
P
5

Something to added:

QGraphicsView::resetMatrix() is equal to QGraphicsView::resetTransform(), which can see from source code:

void QGraphicsView::resetMatrix()
{
    resetTransform();
}
Pigfish answered 18/6, 2021 at 8:37 Comment(1)
Yes, now you have to use resetTransform() since resetMatrix() has been deprecated.Heshvan

© 2022 - 2024 — McMap. All rights reserved.