当前正在尝试在pyqtgraph中绘制散点图,并尝试拖动绘图项目,但无法找到方法。我已经看过GraphicsScene 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.PlotItem()
pl.plot(x, y, symbol='o')
w.addItem(pl)发布于 2014-03-17 20:58:27
查看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()https://stackoverflow.com/questions/22448229
复制相似问题