[英]How to change shape of pyqtgraph nodes
我目前正在使用pyqtgraph,並希望更改自定義節點的形狀,而無需創建一個全新的NodeCustom文件。 我目前的理解是pyqtgraph.Node的NodeGraphicsItem類中的paint函數管理節點的外觀。
我正在嘗試顯示橢圓節點。 我想覆蓋pyqtgraph的繪制函數並使用自定義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,但這是我的目標。
我想你需要補充一下
def boundingRect(self):
return QtCore.QRectF(0, 0, 200, 100)
如果不是你的答案,我會刪除我的答案......
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.