Qt 如何在Qgraphicscene上画一条线

Qt 如何在Qgraphicscene上画一条线,qt,qt4,Qt,Qt4,实际上,我正在编程一个在QGraphicscene中移动的标尺: QPixmap scale("./images/skala.xpm"); pScene = new QGraphicsScene(this); Label = new QGraphicsView(); pScene->addPixmap(scale); pScene->setSceneRect(ScalePos_X, ScalePos_Y, ScaleWidth, ScaleHeight); Label->set

实际上,我正在编程一个在QGraphicscene中移动的标尺:

QPixmap scale("./images/skala.xpm");
pScene = new QGraphicsScene(this);
Label = new QGraphicsView();
pScene->addPixmap(scale);
pScene->setSceneRect(ScalePos_X, ScalePos_Y, ScaleWidth, ScaleHeight);
Label->setScene(pScene);
Label->show();
移动通过
setscen直立()
完成

现在我想画一条固定的中间线,标记比例的中间(pScene的中间)。 我可以在QGraphicscene内画一条线,但这条线在移动场景时正在移动(逻辑上)


是否可以在QGraphicscene上方画一条线?

您可以在
QGraphicsView
对象上安装事件过滤器,截取绘制事件,并使用
QPaint
绘制额外的线。或者,您可以子类化
QGraphicsView
并重新实现其
paintEvent
。您可以使用QGraphicsLineItem绘制一条线,并将项ass的标志设置为QGraphicsSitem::ItemIgnoresTransformations。