qt - graphicsView scale 在 difficultground 中忽略

标签 qt qgraphicsview

我刚刚在 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());
    }

我通过

缩放 View
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() 但没有成功..

最佳答案

如果将线条聚合到一个从 QGraphicsItem 派生的对象中并将该项目添加到场景中,则可以设置标志 QGraphicsItem::ItemIgnoresTransformations,以停止它响应缩放和其他转换。

关于qt - graphicsView scale 在 difficultground 中忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17183441/

相关文章:

Qt QGraphicsView 不播放任何视频

c++ - 如何在QT中打开svg文件(QGraphicsView)

python - 属性错误 : QDialog object has no attribute setCentralWidget

c++ - 读/写同一配置文件不同版本的设计方法

android - 解决 QString 移动错误

c++ - Qt 小部件和指针

python - 限制qgraphicitem的可移动区域

c++ - 在 QGraphicsView 上锁定 View

c++ - Qt:让选定的项目出现在 QGraphicsScene 的顶部

c++ - Qt 中的线插值?