from PySide6.QtCore import QRectF, Qt from PySide6.QtGui import QBrush, QPainter, QPen from PySide6.QtWidgets import QGraphicsEllipseItem, QGraphicsItem, QStyleOptionGraphicsItem, QWidget class SphereGraphicsItem(QGraphicsEllipseItem): SPHERE_WIDTH = 30 def __init__(self, x_pos: int, y_pos: int) -> None: super().__init__(self.SPHERE_WIDTH/2, self.SPHERE_WIDTH/2, self.SPHERE_WIDTH, self.SPHERE_WIDTH) print(f"sphere at {x_pos}:{y_pos}") self.setPos(x_pos, y_pos) brush = QBrush(Qt.GlobalColor.darkBlue) self.setBrush(brush) pen = QPen(Qt.GlobalColor.blue) pen.setWidth(3) self.setPen(pen) self.show() class ArcGraphicsItem(QGraphicsItem): def __init__(self, x_pos: int, y_pos: int, width: int, angle_start: int, angle_end: int, parent: QGraphicsItem | None = ...): super().__init__(parent) print(f"arc from {x_pos}:{y_pos} of {width} {angle_start}° {angle_end}°") self.x_pos = x_pos self.y_pos = y_pos self.width = width self.angle_start = angle_start self.angle_end = angle_end def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem, widget: QWidget | None = ...) -> None: shift = int(self.width/2) painter.drawArc(self.x_pos-shift, self.y_pos-shift, self.width*2, self.width*2, self.angle_start*16, self.angle_end*16) def boundingRect(self) -> QRectF: return QRectF(0, 0, self.x_pos, self.y_pos) class LineGraphicsItem(QGraphicsItem): def __init__(self, begin_x: int, begin_y: int, end_x: int, end_y: int, parent: QGraphicsItem | None = ...) -> None: super().__init__(parent) print(f"line from {begin_x}:{begin_y} to {end_x}:{end_y}") self.begin_x = begin_x self.begin_y = begin_y self.end_x = end_x self.end_y = end_y def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem, widget: QWidget | None = ...) -> None: painter.drawLine(self.begin_x, self.begin_y, self.end_x, self.end_y) def boundingRect(self) -> QRectF: return QRectF(self.begin_x, self.begin_y, self.end_x, self.end_y)