QNodeEditor.graphics.view.NodeView#

class QNodeEditor.graphics.view.NodeView(scene_graphics: ~QNodeEditor.graphics.scene.NodeSceneGraphics, theme: ~typing.Type[~QNodeEditor.themes.theme.Theme] = <class 'QNodeEditor.themes.dark.DarkTheme'>, allow_multiple_inputs: bool = False)#

Bases: QGraphicsView

Extension of QGraphicsView for viewing and interacting with a node scene.

A NodeView displays a scene.

Properties

STATE_CUTTING

Cutting state (a Cutter is being drawn)

STATE_DEFAULT

Default state (no action taking place)

STATE_DRAGGING

Dragging state (a new edge is being dragged)

STATE_PLACING

Placing state (a item or group of items is being placed)

theme

Get or set the node view theme.

Methods

__init__

Create a new node view.

add_node

Start placing a node of the specified type.

align_selection

Align the currently selected items along an axis in the specified direction.

calculate_drag_pos

Calculate the end position of the dragged edge based on the mouse location.

closest_socket

Find the socket closest to a position.

contextMenuEvent

Open the custom context menu at the clicked position.

create_context_menu

Create a context menu at the specified position.

duplicate_node

Duplicate an instance of a node and start placing it.

duplicate_selection

Duplicate the selected items and start placing them.

end_drag

Stop dragging an edge and if applicable create a persistent edge.

get_drag_socket

Get the socket a dragged edge should connect to.

keyPressEvent

Handle key presses.

left_mouse_button_press

Handle left mouse button press.

left_mouse_button_release

Handle left mouse button release.

middle_mouse_button_press

Handle middle mouse button press.

middle_mouse_button_release

Handle middle mouse button release.

mouseMoveEvent

Listen for mouse movement.

mousePressEvent

Listen for mouse button press.

mouseReleaseEvent

Listen for mouse button release.

mouse_dragged

Determine if the mouse was dragged more than some threshold.

mouse_move

Handle mouse movement.

move_selection

Move the center point of the selected items to a specified position.

remove_selected

Remove all selected items from the scene.

right_mouse_button_press

Handle right mouse button press.

right_mouse_button_release

Handle right mouse button release.

set_editing_flag

Set a flag to indicate that node content is (not) being edited.

space_selection

Space the currently selected items in the specified direction.

start_drag

Start dragging an edge from this socket.

wheelEvent

Handle mouse scrolls.

zoom_in

Zoom in by one step.

zoom_out

Zoom out by one step.

zoom_reset

Reset the zoom level to its initial value.

__init__(scene_graphics: ~QNodeEditor.graphics.scene.NodeSceneGraphics, theme: ~typing.Type[~QNodeEditor.themes.theme.Theme] = <class 'QNodeEditor.themes.dark.DarkTheme'>, allow_multiple_inputs: bool = False)#

Create a new node view.

Parameters:
  • scene_graphics (NodeSceneGraphics) – Scene graphics this view is for.

  • theme (Type[Theme], optional) – Theme for the node view (default: DarkTheme)

  • allow_multiple_inputs (bool) – If True, multiple edges can be connected to a single input, otherwise only a single edge can be connected to any input.

align_selection(axis: Orientation = 1, direction: Alignment = 1) None#

Align the currently selected items along an axis in the specified direction.

Specifying Qt.AlignHCenter or Qt.AlignVCenter will both default to center the items along the specified axis (not for both).

Parameters:
  • axis (Orientation) – Axis to align on (Qt.Horizontal or Qt.Vertical)

  • direction (Alignment) – Direction to align items in

Return type:

None

Raises:

ValueError – If no items are selected

contextMenuEvent(event: QContextMenuEvent | None) None#

Open the custom context menu at the clicked position.

Parameters:

event (QContextMenuEvent, optional) – Context menu event

Return type:

None

remove_selected() None#

Remove all selected items from the scene.

Return type:

None

set_editing_flag(editing: bool) None#

Set a flag to indicate that node content is (not) being edited.

When the flag is set to True, items will not be deleted when pressing Del. This prevents accidental removal of scene items while typing in a text box.

Parameters:

editing (bool) – Whether content is being edited in the scene

Return type:

None

space_selection(axis: Orientation = 2, distance: str = 'equal') None#

Space the currently selected items in the specified direction.

Distance can be:

  • 'equal': Equally space the items

  • 'compress': Remove the spacing between the items

Parameters:
  • axis (Orientation) – Axis to align on (Qt.Horizontal or Qt.Vertical)

  • distance (str) – How to space items ('equal' or 'compress')

Return type:

None

zoom_in() None#

Zoom in by one step.

Return type:

None

zoom_out() None#

Zoom out by one step.

Return type:

None

zoom_reset() None#

Reset the zoom level to its initial value.

Return type:

None

STATE_CUTTING: int = 1#

Cutting state (a Cutter is being drawn)

Type:

int

STATE_DEFAULT: int = 0#

Default state (no action taking place)

Type:

int

STATE_DRAGGING: int = 2#

Dragging state (a new edge is being dragged)

Type:

int

STATE_PLACING: int = 3#

Placing state (a item or group of items is being placed)

Type:

int

property theme: Type[Theme]#

Get or set the node view theme.