2013-06-19 26 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,停止它響應縮放和其他轉換。