Qt画家路径在缩放级别不可见

时间:2015-05-05 00:06:15

标签: qt qt5 qgraphicsview qgraphicsitem

我使用自定义的QGraphicsView来显示连接图(只是节点和边缘)。在某些缩放级别,一切都显示正常但是当我放大一点点连接边缘(使用QPainterPath绘制)消失。但是,其他所有东西(矩形,多边形等)都会绘制。如何阻止边缘消失?

这是我的边缘对象的paint方法,它派生自QGraphicsItem(mPath是一个QPainterPath):

void GraphEdgeVisual::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    painter->save();
    painter->drawPath(*mPath);
    // Arrow child will draw itself

    painter->restore();
}

图形视图的主要自定义是允许通过鼠标滚轮放大/缩小。这是我的代码:

MyGraphicsView::MyGraphicsView(QWidget *parent) : QGraphicsView(parent)
{
    // taken from http://www.qtcentre.org/wiki/index.php?title=QGraphicsView:_Smooth_Panning_and_Zooming
    setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);

    //Use ScrollHand Drag Mode to enable Panning
    setDragMode(ScrollHandDrag);
}

/**
  * Zoom the view in and out.
  */
// taken from http://www.qtcentre.org/wiki/index.php?title=QGraphicsView:_Smooth_Panning_and_Zooming
void MyGraphicsView::wheelEvent(QWheelEvent* event)
{
    setTransformationAnchor(QGraphicsView::AnchorUnderMouse);

    // Scale the view / do the zoom
    double scaleFactor = 1.15;
    if(event->delta() > 0) {
        // Zoom in
        scale(scaleFactor, scaleFactor);
    } else {
        // Zooming out
        scale(1.0 / scaleFactor, 1.0 / scaleFactor);
    }

    // Don't call superclass handler here
    // as wheel is normally used for moving scrollbars
}

0 个答案:

没有答案