123456789101112131415161718192021222324252627282930313233343536 |
- """
- QGraphics representation class for a node
- """
- from PyQt5.QtWidgets import QGraphicsItem, QStyleOptionGraphicsItem, QWidget
- from PyQt5.Qt import QRectF, QPainter, QFont, Qt
- class GraphicsNodeItem(QGraphicsItem):
- def __init__(self, node_id, node_type=""):
- QGraphicsItem.__init__(self)
- self.node_id = node_id
- self._type = node_type
- self._font = QFont()
- self._font.setPixelSize(12)
- def set_type(self, node_type):
- self._type = node_type
- self.update(self.boundingRect())
- def get_type(self):
- return self._type
- def boundingRect(self):
- bbox = QRectF(0, 0, 120, 120)
- return bbox
- def paint(self, painter, option, widget=None):
- # type: (QPainter, QStyleOptionGraphicsItem, QWidget) -> None
- painter.setFont(self._font)
- painter.drawRect(self.boundingRect())
- text_box = QRectF(0, 100, 120, 20)
- painter.drawRect(text_box)
- painter.drawText(text_box, Qt.AlignCenter | Qt.TextDontClip, self._type)
|