""" Edge representation for Qt: Same as a LineItem, but stores items it is connected to as well as the modelverse edge id. """ from PyQt5.QtWidgets import QGraphicsItem, QGraphicsLineItem from sketchUI.graphics_node_item import GraphicsNodeItem class GraphicsEdgeItem(QGraphicsLineItem): def __init__(self, from_item, to_item, edge_id=None): #type: (GraphicsNodeItem, GraphicsNodeItem) -> None QGraphicsLineItem.__init__(self) self.from_item = from_item self.to_item = to_item self.edge_id = edge_id self.setFlag(QGraphicsItem.ItemIsMovable, False) self.setFlag(QGraphicsItem.ItemIsSelectable, True) self.setZValue(-1.0) def redraw(self): from_pos = self.from_item.scenePos() from_brect = self.from_item.boundingRect() to_pos = self.to_item.scenePos() to_brec = self.to_item.boundingRect() self.setLine(from_pos.x() + int(from_brect.width()/2.0), from_pos.y() + int(from_brect.height()/2.0), to_pos.x() + int(to_brec.width()/2.0), to_pos.y() + int(to_brec.height()/2.0))