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:
QGraphicsViewExtension of QGraphicsView for viewing and interacting with a node scene.
A
NodeViewdisplays a scene.Properties
Cutting state (a
Cutteris being drawn)Default state (no action taking place)
Dragging state (a new edge is being dragged)
Placing state (a item or group of items is being placed)
Get or set the node view theme.
Methods
Create a new node view.
add_nodeStart placing a node of the specified type.
Align the currently selected items along an axis in the specified direction.
calculate_drag_posCalculate the end position of the dragged edge based on the mouse location.
closest_socketFind the socket closest to a position.
Open the custom context menu at the clicked position.
create_context_menuCreate a context menu at the specified position.
duplicate_nodeDuplicate an instance of a node and start placing it.
duplicate_selectionDuplicate the selected items and start placing them.
end_dragStop dragging an edge and if applicable create a persistent edge.
get_drag_socketGet the socket a dragged edge should connect to.
keyPressEventHandle key presses.
left_mouse_button_pressHandle left mouse button press.
left_mouse_button_releaseHandle left mouse button release.
middle_mouse_button_pressHandle middle mouse button press.
middle_mouse_button_releaseHandle middle mouse button release.
mouseMoveEventListen for mouse movement.
mousePressEventListen for mouse button press.
mouseReleaseEventListen for mouse button release.
mouse_draggedDetermine if the mouse was dragged more than some threshold.
mouse_moveHandle mouse movement.
move_selectionMove the center point of the selected items to a specified position.
Remove all selected items from the scene.
right_mouse_button_pressHandle right mouse button press.
right_mouse_button_releaseHandle right mouse button release.
Set a flag to indicate that node content is (not) being edited.
Space the currently selected items in the specified direction.
start_dragStart dragging an edge from this socket.
wheelEventHandle mouse scrolls.
Zoom in by one step.
Zoom out by one step.
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.AlignHCenterorQt.AlignVCenterwill both default to center the items along the specified axis (not for both).- Parameters:
axis (Orientation) – Axis to align on (
Qt.HorizontalorQt.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 pressingDel. 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.HorizontalorQt.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_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