sas*_*alm 3 c++ qt qgraphicsview
无论之前应用何种比例,如何重置图形视图的比例?使用scale()乘以我给它的前一个刻度:
ui->graphicsView->scale(0.1, 0.1);
ui->graphicsView->scale(2, 2);
// the scale factor is (0.2,0.2), NOT (2,2)
Run Code Online (Sandbox Code Playgroud)
这不是我想要的,我想把比例设置为(2,2).
sas*_*alm 10
我查看了源代码并scale()在内部使用了一个矩阵:
void QGraphicsView::scale(qreal sx, qreal sy)
{
Q_D(QGraphicsView);
QTransform matrix = d->matrix;
matrix.scale(sx, sy);
setTransform(matrix);
}
Run Code Online (Sandbox Code Playgroud)
有一个重置矩阵的功能,并在应用比例之前调用它:
view->scale(0.1, 0.1);
view->resetMatrix();
view->scale(2, 2);
// the scale factor is (2,2)
Run Code Online (Sandbox Code Playgroud)
小智 5
补充一下:
QGraphicsView::resetMatrix() 等于 QGraphicsView::resetTransform(),从源码可以看到:
void QGraphicsView::resetMatrix()
{
resetTransform();
}
Run Code Online (Sandbox Code Playgroud)