graphics_edge_item.py 769 B

123456789101112131415161718192021222324
  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):
  7. QGraphicsLineItem.__init__(self)
  8. self._from_item = from_item
  9. self._to_item = to_item
  10. self.setFlag(QGraphicsItem.ItemIsMovable, False)
  11. self.setFlag(QGraphicsItem.ItemIsSelectable, False)
  12. def redraw(self):
  13. from_pos = self._from_item.scenePos()
  14. to_pos = self._to_item.scenePos()
  15. self.setLine(from_pos.x(), from_pos.y(), to_pos.x(), to_pos.y())
  16. # hack to work around failing isinstance check due to import chaos
  17. def __hack__(self):
  18. return None