How to reset the scale in QGraphicsView?

北城余情 提交于 2019-12-10 18:09:53

问题


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), NOT (2,2)

This is not what I want, I want to just set the scale to (2,2).


回答1:


I looked into the sources and scale() uses a matrix internally:

void QGraphicsView::scale(qreal sx, qreal sy)
{
    Q_D(QGraphicsView);
    QTransform matrix = d->matrix;
    matrix.scale(sx, sy);
    setTransform(matrix);
}

There is a function to reset 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)


来源:https://stackoverflow.com/questions/39101833/how-to-reset-the-scale-in-qgraphicsview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!