graphics_sketch_line.py 946 B

123456789101112131415161718192021222324252627282930313233
  1. """
  2. A QGraphicsLineItem, augmented with the two points it is defined by.
  3. Required since, when in a group, the QGraphicsScene does not update the internal
  4. points of the underlying QLine object, so we update them manually whenever the group is moved.
  5. """
  6. from PyQt5.QtWidgets import QGraphicsLineItem
  7. from PyQt5.Qt import QPointF
  8. class SketchedLineItem(QGraphicsLineItem):
  9. def __init__(self, p1_x, p1_y, p2_x, p2_y):
  10. QGraphicsLineItem.__init__(self, p1_x, p1_y, p2_x, p2_y)
  11. # store away scene coordinates of points
  12. self._p1 = QPointF(p1_x, p1_y)
  13. self._p2 = QPointF(p2_x, p2_y)
  14. def set_p1(self, point):
  15. # type: (QPointF) -> None
  16. self._p1 = point
  17. def set_p2(self, point):
  18. # type: (QPointF) -> None
  19. self._p2 = point
  20. def get_p1(self):
  21. # type: () -> QPointF
  22. return self._p1
  23. def get_p2(self):
  24. # type: () -> QPointF
  25. return self._p2