我刚刚在背景中的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()但是徒劳无功..
答案 0 :(得分:2)
如果将行聚合到从QGraphicsItem派生的对象并将该项添加到场景中,则可以设置标志QGraphicsItem :: ItemIgnoresTransformations,以阻止它响应缩放和其他转换。