Skip to content

graphics_node_subtitle

graphics_node_subtitle

Classes

GraphicsNodeSubtitle(gr_node)

Bases: QGraphicsSimpleTextItem

Extra text under the title of a graphics node. Not editable.

Long text is elided in the middle, so a path keeps both of its ends, and the full text is shown as a tooltip. The item takes no room while it has no text.

Initialize GraphicsNodeSubtitle.

Parameters:

Name Type Description Default
gr_node GraphicsNode

graphics node the subtitle belongs to.

required
Source code in src/nyx/editor/graphics/graphics_node_subtitle.py
27
28
29
30
31
32
33
34
35
36
37
38
39
def __init__(self, gr_node: GraphicsNode):
    """Initialize GraphicsNodeSubtitle.

    Args:
        gr_node (GraphicsNode): graphics node the subtitle belongs to.
    """
    super().__init__(gr_node)
    self.gr_node = gr_node
    self._full_text = ""
    self.setFont(self.SUBTITLE_FONT)
    self.setBrush(QtGui.QBrush(self.COLOR))
    self.setAcceptedMouseButtons(QtCore.Qt.MouseButton.NoButton)
    self.setVisible(False)
Attributes
COLOR = QtGui.QColor('#9A9A9A') class-attribute instance-attribute
HEADER_PADDING = 4.0 class-attribute instance-attribute
MAX_WIDTH = 200.0 class-attribute instance-attribute
SUBTITLE_FONT = QtGui.QFont('Zed Mono', 8) class-attribute instance-attribute
TITLE_OVERLAP = 2.0 class-attribute instance-attribute
full_text property

str: the text as given, before eliding.

gr_node = gr_node instance-attribute
height property

float: height the subtitle adds to the header, 0 without text.

width property

float: width of the shown text, 0 without text.

Functions
paint(painter, option, widget=None)

Draw the text unless it is too small to read.

Parameters:

Name Type Description Default
painter QPainter

painter.

required
option QStyleOptionGraphicsItem

style options.

required
widget QWidget | None

painted widget.

None
Source code in src/nyx/editor/graphics/graphics_node_subtitle.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def paint(
    self,
    painter: QtGui.QPainter,
    option: QtWidgets.QStyleOptionGraphicsItem,
    widget: QtWidgets.QWidget | None = None,
) -> None:
    """Draw the text unless it is too small to read.

    Args:
        painter (QtGui.QPainter): painter.
        option (QtWidgets.QStyleOptionGraphicsItem): style options.
        widget (QtWidgets.QWidget | None): painted widget.
    """
    lod = LevelOfDetail.from_painter(
        painter, text_size=self.SUBTITLE_FONT.pointSizeF()
    )
    if lod.shows_text:
        super().paint(painter, option, widget)
refresh(text)

Show a text.

Parameters:

Name Type Description Default
text str

subtitle of the node, empty for none.

required

Returns:

Type Description
bool

text changed, so the owner needs a new layout.

Source code in src/nyx/editor/graphics/graphics_node_subtitle.py
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def refresh(self, text: str) -> bool:
    """Show a text.

    Args:
        text (str): subtitle of the node, empty for none.

    Returns:
        bool: text changed, so the owner needs a new layout.
    """
    if text == self._full_text:
        return False
    self._full_text = text
    shown = QtGui.QFontMetricsF(self.font()).elidedText(
        text, QtCore.Qt.TextElideMode.ElideMiddle, self.MAX_WIDTH
    )
    self.setText(shown)
    self.setToolTip(text if shown != text else "")
    self.setVisible(bool(text))
    return True