我目前正在使用pyqtgraph,并且想要更改自定义节点的形状而不创建一个新的NodeCustom文件。我目前的理解是pyqtgraph.Node的NodeGraphicsItem类中的paint函数管理节点的外观。
我正在尝试显示一个椭圆节点。 我想覆盖pyqtgraph的paint功能,并使用自定义的drawEllipse方法。
class EllipseNodeItem(Node):
nodeName = "EllipseNode"
def __init__(self, name):
self.view = None
# Initialize node with only a single input terminal
n = Node.__init__(self, name, terminals={'data': {'io': 'in'}})
#NodeGraphicsItem.__init__(self, n)
# drawing node in shape of ellipse, fitting into rectangle 200x100
def paint(self, p, *args): # pyqt function
self.bounds = QtCore.QRectF(0, 0, 200, 100)
p.setPen(self.pen)
if self.isSelected(): #or self in sm.selectedNodes:
p.setPen(self.selectPen)
p.setBrush(self.selectBrush)
else:
p.setPen(self.pen)
if self.hovered:
p.setBrush(self.hoverBrush)
else:
p.setBrush(self.brush)
p.drawEllipse(self.bounds)
def setView(self, view): # setView must be called by the program
self.view = view
def process(self, data, display=True):
if display and self.view is not None:
# the 'data' argument is the value given to the 'data' terminal
if data is None:
self.view.setImage(np.zeros((1, 1))) # give a blank array to clear the view
else:
self.view.setImage(data)
它确实将EllipseNode视为单独的可选节点。显然,导入的Node和NodeGraphicsItem类不使用paint,但这是我的目标。
答案 0 :(得分:0)
我认为您需要添加
def boundingRect(self):
return QtCore.QRectF(0, 0, 200, 100)
如果这不是您的答案,我将删除我的答案...