如何在QGraphicsView中重置比例

How to reset the scale in QGraphicsView?

本文关键字:QGraphicsView      更新时间:2023-10-16

如何重置图形视图的比例,而不管之前应用的任何比例?使用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();
}