Python 在QGraphicsView中显示X和Y坐标线

Python 在QGraphicsView中显示X和Y坐标线,python,pyqt,pyqt5,qgraphicsview,qgraphicsscene,Python,Pyqt,Pyqt5,Qgraphicsview,Qgraphicsscene,我想在QGraphicsView中显示一个图像,实际上在Qgraphicscene中,这是最简单的部分,bu,当我将光标移动到图像上时,我想看到X和Y坐标线,如图中的黄线,有人能告诉我怎么做吗 要实现您想要的,有两项任务: 获取光标的位置,在这种情况下,启用该标志,以便在获取位置的位置调用该标志 在顶层绘制,为此我们使用函数 从PyQt5导入QtCore、QtGui、QtWidgets 类graphicsceneqtwidts.qgraphicscene: def drawForegrounds

我想在QGraphicsView中显示一个图像,实际上在Qgraphicscene中,这是最简单的部分,bu,当我将光标移动到图像上时,我想看到X和Y坐标线,如图中的黄线,有人能告诉我怎么做吗


要实现您想要的,有两项任务:

获取光标的位置,在这种情况下,启用该标志,以便在获取位置的位置调用该标志

在顶层绘制,为此我们使用函数

从PyQt5导入QtCore、QtGui、QtWidgets 类graphicsceneqtwidts.qgraphicscene: def drawForegroundself,油漆工,矩形: Supergraphicscene,self.drawForegroundpainter,rect 如果不是hasattrself,光标位置: 回来 救命 pen=QtGui.QPenQtGui.QColoryellow pen.setWidth4 画师 linex=QtCore.QLineF 右,左, self.cursor_position.y, 对, self.cursor_position.y, liney=QtCore.QLineF self.cursor_position.x, 右上角, self.cursor_position.x, 矩形底部, 对于linex中的线,liney: 钢丝绳 修复 def mouseMoveEventself,事件: self.cursor\u position=event.scenePos 自我更新 Supergraphicscene,self.mousemoveevent 类GraphicsView QTWidgets.QGraphicsView: def u_init__self,父项=无: superGraphicsView,self.\u初始化\u父级 self.setMouseTrackingTrue 场景=graphicsceneqtcore.QRectF-200,-200400400,self 自我设定 如果uuuu name uuuuu==\uuuuuuuu main\uuuuuuuu: 导入系统 随机输入 app=qtwidts.QApplicationsys.argv w=图形视图 对于范围4中的uu: r=QtCore.QRectF *random.samplerange-200200,2, *随机抽样:50、150、2 it=w.scene.addRectr it.setBrushQtGui.QColor*random.samplerange255,3 w、 调整尺寸640480 w、 展示 sys.exitapp.exec_
要实现您想要的,有两项任务:

获取光标的位置,在这种情况下,启用该标志,以便在获取位置的位置调用该标志

在顶层绘制,为此我们使用函数

从PyQt5导入QtCore、QtGui、QtWidgets 类graphicsceneqtwidts.qgraphicscene: def drawForegroundself,油漆工,矩形: Supergraphicscene,self.drawForegroundpainter,rect 如果不是hasattrself,光标位置: 回来 救命 pen=QtGui.QPenQtGui.QColoryellow pen.setWidth4 画师 linex=QtCore.QLineF 右,左, self.cursor_position.y, 对, self.cursor_position.y, liney=QtCore.QLineF self.cursor_position.x, 右上角, self.cursor_position.x, 矩形底部, 对于linex中的线,liney: 钢丝绳 修复 def mouseMoveEventself,事件: self.cursor\u position=event.scenePos 自我更新 Supergraphicscene,self.mousemoveevent 类GraphicsView QTWidgets.QGraphicsView: def u_init__self,父项=无: superGraphicsView,self.\u初始化\u父级 self.setMouseTrackingTrue 场景=graphicsceneqtcore.QRectF-200,-200400400,self 自我设定 如果uuuu name uuuuu==\uuuuuuuu main\uuuuuuuu: 导入系统 随机输入 app=qtwidts.QApplicationsys.argv w=图形视图 对于范围4中的uu: r=QtCore.QRectF *random.samplerange-200200,2, *随机抽样:50、150、2 it=w.scene.addRectr it.setBrushQtGui.QColor*random.samplerange255,3 w、 调整尺寸640480 w、 展示 sys.exitapp.exec_