PlotDataItem
is a wrapper around a PlotCurveItem
and a ScatterPlotItem
. As such, it does not actually have any graphics or a clickable shape of its own. I would try making a subclass of PlotCurveItem
instead. If you really need to use PlotDataItem
, then it is possible to modify it such that it inherits its shape from the wrapped curve:
class CustomPlotItem(pg.PlotDataItem):
def __init__(self, *args, **kargs):
super().__init__(*args, **kargs)
# Need to switch off the "has no contents" flag
self.setFlags(self.flags() & ~self.ItemHasNoContents)
def mouseDragEvent(self, ev):
print("drag")
if ev.button() != QtCore.Qt.LeftButton:
ev.ignore()
return
if ev.isStart():
print("start")
elif ev.isFinish():
print("finish")
def shape(self):
# Inherit shape from the curve item
return self.curve.shape()
def boundingRect(self):
# All graphics items require this method (unless they have no contents)
return self.shape().boundingRect()
def paint(self, p, *args):
# All graphics items require this method (unless they have no contents)
return
def hoverEvent(self, ev):
# This is recommended to ensure that the item plays nicely with
# other draggable items
print("hover")
ev.acceptDrags(QtCore.Qt.LeftButton)