如何重置 QGraphicsView 中的比例?

How to reset the scale in QGraphicsView?

如何重新设置图形视图的比例而不考虑之前应用的任何比例?使用 scale() 将我给它的比例乘以前一个:

ui->graphicsView->scale(0.1, 0.1);
ui->graphicsView->scale(2, 2);
// the scale factor is (0.2,0.2) instead of (2,2)

QGraphicsView::resetMatrix() 重置矩阵,并在应用比例之前调用它:

view->scale(0.1, 0.1);
view->resetMatrix();
view->scale(2, 2);
// the scale factor is (2,2)

要补充的内容:

QGraphicsView::resetMatrix()等于QGraphicsView::resetTransform(),从源码可以看出:

void QGraphicsView::resetMatrix()
{
    resetTransform();
}