Python pyqtgraph:如何拖动绘图项
当前正在尝试在pyqtgraph中绘制散点图,并尝试拖动绘图项目,但找不到方法。 已经查看了Graphicscene sigMouseClicked、sigMouseMoved事件。 欢迎任何建议。 如果需要我方提供更多细节,请告诉我 我正在使用的示例代码:Python pyqtgraph:如何拖动绘图项,python,plot,qgraphicsscene,pyqtgraph,Python,Plot,Qgraphicsscene,Pyqtgraph,当前正在尝试在pyqtgraph中绘制散点图,并尝试拖动绘图项目,但找不到方法。 已经查看了Graphicscene sigMouseClicked、sigMouseMoved事件。 欢迎任何建议。 如果需要我方提供更多细节,请告诉我 我正在使用的示例代码: import pyqtgraph as pg import numpy as np w = pg.GraphicsWindow() w.show() x = [2,4,5,6,8]; y = [2,4,6,8,10]; pl = pg.
import pyqtgraph as pg
import numpy as np
w = pg.GraphicsWindow()
w.show()
x = [2,4,5,6,8];
y = [2,4,6,8,10];
pl = pg.PlotItem()
pl.plot(x, y, symbol='o')
w.addItem(pl)
请查看pyqtgraph/examples/CustomGraphItem.py。 这里的方法是创建一个GraphItem子类,用于捕获鼠标拖动事件并移动鼠标下的散点图点:
def mouseDragEvent(self, ev):
if ev.button() != QtCore.Qt.LeftButton:
ev.ignore()
return
if ev.isStart():
# We are already one step into the drag.
# Find the point(s) at the mouse cursor when the button was first
# pressed:
pos = ev.buttonDownPos()
pts = self.scatter.pointsAt(pos)
if len(pts) == 0:
ev.ignore()
return
self.dragPoint = pts[0]
ind = pts[0].data()[0]
self.dragOffset = self.data['pos'][ind] - pos
elif ev.isFinish():
self.dragPoint = None
return
else:
if self.dragPoint is None:
ev.ignore()
return
ind = self.dragPoint.data()[0]
self.data['pos'][ind] = ev.pos() + self.dragOffset
self.updateGraph()
ev.accept()
谢谢你的回复,但是我在我的文件夹下找不到相关的例子。请在此分享完整示例,以供我理解。对不起,可能尚未发布: