简体   繁体   English

GraphicsView中的网格

[英]Grid in GraphicsView

I want to implement grid in my graphicsView such that it fits to the graphicsView automatically and when I zoom in the graphicsView only the block size of grid should increase but not the line width of the grid. 我想在我的graphicsView中实现网格,以使其自动适合graphicsView,并且当我放大graphicsView时,仅网格的块大小应该增加,而不是网格的线宽。 I tried the following but nothing happened. 我尝试了以下操作,但没有任何反应。

void CadGraphicsScene::grid(QPainter *painter, const QRectF &rect)
{
    QPen pen;
    painter->setPen(pen);

    qreal left = int(rect.left()) - (int(rect.left()) % gridSize);
    qreal top = int(rect.top()) - (int(rect.top()) % gridSize);
    QVector<QPointF> points;
    for (qreal x = left; x < rect.right(); x += gridSize){
        for (qreal y = top; y < rect.bottom(); y += gridSize){
            points.append(QPointF(x,y));
        }
    }
    painter->drawPoints(points.data(), points.size());
}

Please help me out to make a grid. 请帮我做一个网格。

1)使用化妆笔(宽度为零)2)通过QT习语,图形场景与视图无关(关于您在graphicsview中的缩放问题),但是您可以从传递的QPainter对象(QPainter * painter)-QPainter中提取视图的缩放系数:: worldTransform-> QTransform :: m11(horz_Scale)和QTransform :: m22(vert_Scale)-在这种情况下,您可以重新计算网格锚(对于100%缩放,QTransform :: m11 == QTransform :: m22 == 1) '飞'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM