QGraphicsView和QGraphicsScene中添加了一张图片,如何在图片上绘制两点之间虚线?

QGraphicsView和QGraphicsScene中添加了一张图片,
如何在图片上绘制两点之间虚线?

.......
m_GraView->setScene(m_GraScene);
m_GraView->resize(this->width(), this->height());
m_GraView->setStyleSheet("background: black;border:0px");
m_GraScene->addPixmap(m_pixmap );

两点之间绘制虚线主要功能就是测量两点之间的距离,点的坐标可以获取,但是我不知道如何绘制虚线?

假设你的class 为 T

void T::paintLine(QPixmap &pix, QPoint point1, QPoint point2)
{
    if(!pix.isNull())
    {
        QPainter painter(&pix);
        QPen pen;
        pen.setWidth(2);
        pen.setStyle(Qt::DashLine);
        pen.setColor(Qt::blue);
        painter.setPen(pen);
        painter.drawLine(point1,point2);
    }
}

https://blog.csdn.net/dinjay/article/details/7814849