我刚刚在 QGraphicsView 的背景上绘制了网格线
drawbackground(QPainter *painter, const QRectF &rect)
{
QVarLengthArray<QLineF, 100> linesX;
for (qreal x = left; x < sceneRect.right(); x += gridInterval )
{
linesX.append(QLineF(x, sceneRect.top(), x, sceneRect.bottom()));
}
QVarLengthArray<QLineF, 100> linesY;
for (qreal y = top; y < sceneRect.bottom(); y += gridInterval ){
linesY.append(QLineF(sceneRect.left(), y, sceneRect.right(), y));
}
painter->drawLines(linesX.data(), linesX.size());
painter->drawLines(linesY.data(), linesY.size());
}
我将视图缩放
void
ViewPort::zoomIn()
{
zoom(qreal(1.2));
}
void
ViewPort::zoomOut()
{
zoom(1 / qreal(1.2));
}
void
ViewPort::zoom(qreal scaleFactor)
{
qreal factor = transform().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width();
if (factor < 1 || factor > 100)
return;
scale(scaleFactor, scaleFactor);
}
现在场景有很多我必须缩放的项目,但我需要忽略我在 graphicsView drawBackground 上绘制的网格线。我怎么能忽略gridLines的比例变换。?
我尝试了 QPainter::resetTransform() 但徒劳无功..