2013-06-19 25 views
2

我只是graphicsView规模drawbackground忽略

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); 

} 

绘制网格线中的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()); 
    } 

和IM缩放视图现在风光有大量的项目,我必须比例尺,但我需要忽略我绘制在graphicsView drawBackground上的网格线。 我怎么可以忽略gridLines的尺度转换。

我试过了QPainter :: resetTransform()却徒劳无功..

+0

出于curisoity,为什么不希望网格线与视图的比例缩放(缩放) - 当然网格的整个点是指示比例? – cmannett85

+0

我只是想缩放或放大场景中的物体,如圆形目标,多边形目标和其他像素图目标。所以在视图中,网格线更像是带有轴标记的图形图。 – Wagmare

+0

我必须根据转换的场景更新标记中的比例值。例如:按照sceneRect,默认比例将为x:1000,y:1000。如果我缩放场景到1500,1000,那么我必须更新轴到x:1500,y:1000。 – Wagmare

回答

1

如果您汇总你从派生的QGraphicsItem和项目添加到场景中的行成一个对象,然后你可以设置标志的QGraphicsItem: :ItemIgnoresTransformations,停止它响应缩放和其他转换。