graphics_edge_item.py 810 B

12345678910111213141516171819202122232425
  1. """
  2. Edge representation for Qt: Same as a LineItem, but stores items it is connected to
  3. """
  4. from PyQt5.QtWidgets import QGraphicsItem, QGraphicsLineItem
  5. class GraphicsEdgeItem(QGraphicsLineItem):
  6. def __init__(self, from_item, to_item, edge_id=None):
  7. QGraphicsLineItem.__init__(self)
  8. self.from_item = from_item
  9. self.to_item = to_item
  10. self.edge_id = edge_id
  11. self.setFlag(QGraphicsItem.ItemIsMovable, False)
  12. self.setFlag(QGraphicsItem.ItemIsSelectable, False)
  13. def redraw(self):
  14. from_pos = self.from_item.scenePos()
  15. to_pos = self.to_item.scenePos()
  16. self.setLine(from_pos.x(), from_pos.y(), to_pos.x(), to_pos.y())
  17. # hack to work around failing isinstance check due to import chaos
  18. def __hack__(self):
  19. return None