Class Node
Build from Node.h
Krita 4.0.0Krita master

Node represents a layer or mask in a Krita image's Node hierarchy. Group layers can contain other layers and masks; layers can contain masks.

Methods

addChildNode(child: Node, above: Node)bool alphaLocked()bool animated()bool blendingMode()str bounds()QRect channels()list[Channel] childNodes()list[Node] clone() collapsed()bool colorDepth()str colorLabel()int colorModel()str colorProfile()str cropNode(x: int, y: int, w: int, h: int) duplicate() enableAnimation() findChildNodes(name: str = "", recursive: bool = False, partialMatch: bool = False, type: str = "", colorLabelIndex: int = 0)list[Node] hasExtents()bool hasKeyframeAtTime(frameNumber: int)bool icon()QIcon index()int inheritAlpha()bool isPinnedToTimeline()bool layerStyleToAsl()str locked()bool mergeDown() move(x: int, y: int) name()str opacity()int paintAbility()str paintEllipse(rect: QRectF, strokeStyle: str = PaintingResources::defaultStrokeStyle, fillStyle: str = PaintingResources::defaultFillStyle) paintLine(pointOne: QPointF, pointTwo: QPointF, pressureOne: float = 10, pressureTwo: float = 10, strokeStyle: str = PaintingResources::defaultStrokeStyle) paintPath(path: QPainterPath, strokeStyle: str = PaintingResources::defaultStrokeStyle, fillStyle: str = PaintingResources::defaultFillStyle) paintPolygon(points: list[QPointF], strokeStyle: str = PaintingResources::defaultStrokeStyle, fillStyle: str = PaintingResources::defaultFillStyle) paintRectangle(rect: QRectF, strokeStyle: str = PaintingResources::defaultStrokeStyle, fillStyle: str = PaintingResources::defaultFillStyle) parentNode() pixelData(x: int, y: int, w: int, h: int)QByteArray pixelDataAtTime(x: int, y: int, w: int, h: int, time: int)QByteArray position()QPoint projectionPixelData(x: int, y: int, w: int, h: int)QByteArray remove()bool removeChildNode(child: Node)bool rotateNode(radians: float) save(filename: str, xRes: float, yRes: float, exportConfiguration: InfoObject, exportRect: QRect = QRect())bool scaleNode(origin: QPointF, width: int, height: int, strategy: str) setAlphaLocked(value: bool) setBlendingMode(value: str) setChildNodes(nodes: list[Node]) setCollapsed(collapsed: bool) setColorLabel(index: int) setColorProfile(colorProfile: str)bool setColorSpace(colorModel: str, colorDepth: str, colorProfile: str)bool setInheritAlpha(value: bool) setLayerStyleFromAsl(asl: str)bool setLocked(value: bool) setName(name: str) setOpacity(value: int) setPinnedToTimeline(pinned: bool) setPixelData(value: QByteArray, x: int, y: int, w: int, h: int)bool setShowInTimeline(showInTimeline: bool) setVisible(visible: bool) shearNode(angleX: float, angleY: float) showInTimeline()bool thumbnail(w: int, h: int)QImage uniqueId()QUuid visible()bool

Re-implemented methods

type()str

Member documentation

addChildNode(child: Node, above: Node)bool
Krita 4.0.0

adds the given node in the list of children.

Parameters

child

the node to be added

above

the node above which this node will be placed

Return

false if adding the node failed

alphaLocked()bool
Krita 4.0.0

checks whether the node is a paint layer and returns whether it is alpha locked

Return

whether the paint layer is alpha locked, or false if the node is not a paint layer

animated()bool
Krita 4.0.0

Krita layers can be animated, i.e., have frames.

Return

return true if the layer has frames. Currently, the scripting framework does not give access to the animation features.

blendingMode()str
Krita 4.0.0

Return

the blending mode of the layer. The values of the blending modes are defined in @see KoCompositeOpRegistry.h

bounds()QRect
Krita 4.0.0

return the exact bounds of the node's paint device

Return

the bounds, or an empty QRect if the node has no paint device or is empty.

channels()list[Channel]
Krita 4.0.0

creates a list of Channel objects that can be used individually to show or hide certain channels, and to retrieve the contents of each channel in a node separately.

Only layers have channels, masks do not, and calling channels on a Node that is a mask will return an empty list.

Return

the list of channels ordered in by position of the channels in pixel position

childNodes()list[Node]
Krita 4.0.0Krita 5.2.0

Return

returns a list of child nodes of the current node. The nodes are ordered from the bottommost up. The function is not recursive.

clone()
Krita 4.0.0

clone the current node. The node is not associated with any image.

Return

(no description provided)

collapsed()bool
Krita 4.0.0

returns the collapsed state of this node

Return

(no description provided)

colorDepth()str
Krita 4.0.0

colorDepth A string describing the color depth of the image:

  • U8: unsigned 8 bits integer, the most common type
  • U16: unsigned 16 bits integer
  • F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR
  • F32: 32 bits floating point

Return

the color depth.

colorLabel()int
Krita 4.0.0

Sets a color label index associated to the layer. The actual color of the label and the number of available colors is defined by Krita GUI configuration.

Return

(no description provided)

colorModel()str
Krita 4.0.0

retrieve the current color model of this document:

  • A: Alpha mask
  • RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)
  • XYZA: XYZ with alpha channel
  • LABA: LAB with alpha channel
  • CMYKA: CMYK with alpha channel
  • GRAYA: Gray with alpha channel
  • YCbCrA: YCbCr with alpha channel

Return

the internal color model string.

colorProfile()str
Krita 4.0.0

Return

the name of the current color profile

cropNode(x: int, y: int, w: int, h: int)
Krita 4.0.0

crop this layer.

Parameters

x

the left edge of the cropping rectangle.

y

the top edge of the cropping rectangle

w

the right edge of the cropping rectangle

h

the bottom edge of the cropping rectangle

Krita 4.0.0Krita 4.2.0

returns a full copy of the current node. The node is not inserted in the graphic

Return

a valid Node object or 0 if the node couldn't be duplicated.

Krita 4.0.0

make the current layer animated, so it can have frames.

findChildNodes(name: str = "", recursive: bool = False, partialMatch: bool = False, type: str = "", colorLabelIndex: int = 0)list[Node]
Krita 5.2.0

Parameters

name

name of the child node to search for. Leaving this blank will return all nodes.

recursive

whether or not to search recursively. Defaults to false.

partialMatch

return if the name partially contains the string (case insensitive). Defaults to false.

type

filter returned nodes based on type

colorLabelIndex

filter returned nodes based on color label index

Return

returns a list of child nodes and grand child nodes of the current node that match the search criteria.

hasExtents()bool
Krita 4.1.0

does the node have any content in it?

Return

if node has any content in it

hasKeyframeAtTime(frameNumber: int)bool
Krita 4.2.0

Check to see if frame number on layer is a keyframe

Parameters

frameNumber(no description provided)

Return

(no description provided)

icon()QIcon
Krita 4.0.0

Return

the icon associated with the layer.

index()int
Krita 5.0.0

the index of the node inside the parent

Return

an integer representing the node's index inside the parent

inheritAlpha()bool
Krita 4.0.0

checks whether this node has the inherits alpha flag set

Return

true if the Inherit Alpha is set

isPinnedToTimeline()bool
Krita 5.0.0

Return

Returns true if node is pinned to the Timeline Docker or false if it is not.

layerStyleToAsl()str
Krita 5.0.0Krita 5.2.0

retrieve the current layer's style in ASL format.

Return

a QString in ASL format representing the layer style.

locked()bool
Krita 4.0.0

checks whether the Node is locked. A locked node cannot be changed.

Return

true if the Node is locked, false if it hasn't been locked.

Krita 4.0.0Krita 4.1.2

merges the given node with the first visible node underneath this node in the layerstack. This will drop all per-layer metadata.

Return

(no description provided)

move(x: int, y: int)
Krita 4.0.0

move the pixels to the given x, y location in the image coordinate space.

Parameters

x(no description provided)
y(no description provided)
name()str
Krita 4.0.0

Return

the user-visible name of this node.

opacity()int
Krita 4.0.0

return the opacity of the Node. The opacity is a value between 0 and 255.

Return

(no description provided)

paintAbility()str
Krita master

can be used to determine whether this node can be painted on with the current brush preset.

Return

QString, one of the following:

  • VECTOR - This node is vector-based.
  • CLONE - This node is a Clone Layer.
  • PAINT - This node is paintable by the current brush preset.
  • UNPAINTABLE - This node is not paintable, or a null preset is somehow selected./li>
  • MYPAINTBRUSH_UNPAINTABLE - This node's non-RGBA colorspace cannot be painted on by the currently selected MyPaint brush.

paintEllipse(rect: QRectF, strokeStyle: str = PaintingResources::defaultStrokeStyle, fillStyle: str = PaintingResources::defaultFillStyle)
Krita master

paint an ellipse on the canvas. Uses current brush preset

Parameters

rect

QRect with x, y, width, and height

  • None
  • ForegroundColor
  • BackgroundColor
Default is ForegroundColor.

strokeStyle(no description provided)
fillStyle

appearance of the fill, one of:

  • None
  • ForegroundColor
  • BackgroundColor
  • Pattern
Default is None.

paintLine(pointOne: QPointF, pointTwo: QPointF, pressureOne: float = 10, pressureTwo: float = 10, strokeStyle: str = PaintingResources::defaultStrokeStyle)
Krita master

paint a line on the canvas. Uses current brush preset

Parameters

pointOne

starting point

pointTwo

end point

pressureOne

starting pressure

pressureTwo

end pressure

strokeStyle

appearance of the outline, one of:

  • None - will use Foreground Color, since line would be invisible otherwise
  • ForegroundColor
  • BackgroundColor

paintPath(path: QPainterPath, strokeStyle: str = PaintingResources::defaultStrokeStyle, fillStyle: str = PaintingResources::defaultFillStyle)
Krita master

paint a custom path on the canvas. Uses current brush preset

Parameters

path(no description provided)
strokeStyle(no description provided)
fillStyle

appearance of the fill, one of:

  • None
  • ForegroundColor
  • BackgroundColor
  • Pattern
Default is None.

paintPolygon(points: list[QPointF], strokeStyle: str = PaintingResources::defaultStrokeStyle, fillStyle: str = PaintingResources::defaultFillStyle)
Krita master

paint a polygon on the canvas. Uses current brush preset

Parameters

points(no description provided)
strokeStyle(no description provided)
fillStyle

appearance of the fill, one of:

  • None
  • ForegroundColor
  • BackgroundColor
  • Pattern
Default is None.

paintRectangle(rect: QRectF, strokeStyle: str = PaintingResources::defaultStrokeStyle, fillStyle: str = PaintingResources::defaultFillStyle)
Krita master

paint a rectangle on the canvas. Uses current brush preset

Parameters

rect

QRect with x, y, width, and height

strokeStyle

appearance of the outline, one of:

  • None
  • ForegroundColor
  • BackgroundColor
Default is ForegroundColor.

fillStyle

appearance of the fill, one of:

  • None
  • ForegroundColor
  • BackgroundColor
  • Pattern
Default is None.

Krita 4.0.0

return the Node that is the parent of the current Node, or 0 if this is the root Node.

Return

(no description provided)

pixelData(x: int, y: int, w: int, h: int)QByteArray
Krita 4.0.0

reads the given rectangle from the Node's paintable pixels, if those exist, and returns it as a byte array. The pixel data starts top-left, and is ordered row-first.

The byte array can be interpreted as follows: 8 bits images have one byte per channel, and as many bytes as there are channels. 16 bits integer images have two bytes per channel, representing an unsigned short. 16 bits float images have two bytes per channel, representing a half, or 16 bits float. 32 bits float images have four bytes per channel, representing a float.

You can read outside the node boundaries; those pixels will be transparent black.

The order of channels is:

  • Integer RGBA: Blue, Green, Red, Alpha
  • Float RGBA: Red, Green, Blue, Alpha
  • GrayA: Gray, Alpha
  • Selection: selectedness
  • LabA: L, a, b, Alpha
  • CMYKA: Cyan, Magenta, Yellow, Key, Alpha
  • XYZA: X, Y, Z, A
  • YCbCrA: Y, Cb, Cr, Alpha

The byte array is a copy of the original node data. In Python, you can use bytes, bytearray and the struct module to interpret the data and construct, for instance, a Pillow Image object.

If you read the pixeldata of a mask, a filter or generator layer, you get the selection bytes, which is one channel with values in the range from 0..255.

If you want to change the pixels of a node you can write the pixels back after manipulation with setPixelData(). This will only succeed on nodes with writable pixel data, e.g not on groups or file layers.

Parameters

x

x position from where to start reading

y

y position from where to start reading

w

row length to read

h

number of rows to read

Return

a QByteArray with the pixel data. The byte array may be empty.

pixelDataAtTime(x: int, y: int, w: int, h: int, time: int)QByteArray
Krita 4.0.0

a basic function to get pixeldata from an animated node at a given time.

Parameters

x

the position from the left to start reading.

y

the position from the top to start reader

w

the row length to read

h

the number of rows to read

time

the frame number

Return

a QByteArray with the pixel data. The byte array may be empty.

position()QPoint
Krita 4.0.0Krita 4.1.2

returns the position of the paint device of this node. The position is always 0,0 unless the layer has been moved. If you want to know the topleft position of the rectangle around the actual non-transparent pixels in the node, use bounds().

Return

the top-left position of the node

projectionPixelData(x: int, y: int, w: int, h: int)QByteArray
Krita 4.0.0

reads the given rectangle from the Node's projection (that is, what the node looks like after all sub-Nodes (like layers in a group or masks on a layer) have been applied, and returns it as a byte array. The pixel data starts top-left, and is ordered row-first.

The byte array can be interpreted as follows: 8 bits images have one byte per channel, and as many bytes as there are channels. 16 bits integer images have two bytes per channel, representing an unsigned short. 16 bits float images have two bytes per channel, representing a half, or 16 bits float. 32 bits float images have four bytes per channel, representing a float.

You can read outside the node boundaries; those pixels will be transparent black.

The order of channels is:

  • Integer RGBA: Blue, Green, Red, Alpha
  • Float RGBA: Red, Green, Blue, Alpha
  • GrayA: Gray, Alpha
  • Selection: selectedness
  • LabA: L, a, b, Alpha
  • CMYKA: Cyan, Magenta, Yellow, Key, Alpha
  • XYZA: X, Y, Z, A
  • YCbCrA: Y, Cb, Cr, Alpha

The byte array is a copy of the original node data. In Python, you can use bytes, bytearray and the struct module to interpret the data and construct, for instance, a Pillow Image object.

If you read the projection of a mask, you get the selection bytes, which is one channel with values in the range from 0..255.

If you want to change the pixels of a node you can write the pixels back after manipulation with setPixelData(). This will only succeed on nodes with writable pixel data, e.g not on groups or file layers.

Parameters

x

x position from where to start reading

y

y position from where to start reading

w

row length to read

h

number of rows to read

Return

a QByteArray with the pixel data. The byte array may be empty.

remove()bool
Krita 4.0.0

removes this node from its parent image.

Return

(no description provided)

removeChildNode(child: Node)bool
Krita 4.0.0

removes the given node from the list of children.

Parameters

child

the node to be removed

Return

(no description provided)

rotateNode(radians: float)
Krita 4.0.0

rotate this layer by the given radians.

Parameters

radians

amount the layer should be rotated in, in radians.

save(filename: str, xRes: float, yRes: float, exportConfiguration: InfoObject, exportRect: QRect = QRect())bool
Krita 4.0.0Krita 4.2.0

exports the given node with this filename. The extension of the filename determines the filetype.

Parameters

filename

the filename including extension

xRes

the horizontal resolution in pixels per pt (there are 72 pts in an inch)

yRes

the horizontal resolution in pixels per pt (there are 72 pts in an inch)

exportConfiguration

a configuration object appropriate to the file format.

exportRect

the export bounds for saving a node as a QRect If \p exportRect is empty, then save exactBounds() of the node. If you'd like to save the image- aligned area of the node, just pass image->bounds() there. See Document->exportImage for InfoObject details.

Return

true if saving succeeded, false if it failed.

scaleNode(origin: QPointF, width: int, height: int, strategy: str)
Krita 4.0.0Krita 4.2.0

Parameters

origin

the origin point

width

the width

height

the height

strategy

the scaling strategy. There's several ones amongst these that aren't available in the regular UI.

  • Hermite
  • Bicubic - Adds pixels using the color of surrounding pixels. Produces smoother tonal gradations than Bilinear.
  • Box - Replicate pixels in the image. Preserves all the original detail, but can produce jagged effects.
  • Bilinear - Adds pixels averaging the color values of surrounding pixels. Produces medium quality results when the image is scaled from half to two times the original size.
  • Bell
  • BSpline
  • Lanczos3 - Offers similar results than Bicubic, but maybe a little bit sharper. Can produce light and dark halos along strong edges.
  • Mitchell

setAlphaLocked(value: bool)
Krita 4.0.0

set the layer to value if the node is paint layer.

Parameters

value(no description provided)
setBlendingMode(value: str)
Krita 4.0.0

set the blending mode of the node to the given value

Parameters

value

one of the string values from @see KoCompositeOpRegistry.h

setChildNodes(nodes: list[Node])
Krita 4.0.0

this replaces the existing set of child nodes with the new set.

Parameters

nodes

The list of nodes that will become children, bottom-up -- the first node, is the bottom-most node in the stack.

setCollapsed(collapsed: bool)
Krita 4.0.0

Sets the state of the node to the value of collapsed

Parameters

collapsed

(no description provided)

setColorLabel(index: int)
Krita 4.0.0

sets a color label index associated to the layer. The actual color of the label and the number of available colors is defined by Krita GUI configuration.

Parameters

index

an integer corresponding to the set of available color labels.

setColorProfile(colorProfile: str)bool
Krita 4.0.0Krita 4.2.0

set the color profile of the image to the given profile. The profile has to be registered with krita and be compatible with the current color model and depth; the image data is not converted.

Parameters

colorProfile

(no description provided)

Return

if assigning the color profile worked

setColorSpace(colorModel: str, colorDepth: str, colorProfile: str)bool
Krita 4.0.0

convert the node to the given colorspace

Parameters

colorModel

A string describing the color model of the node:

  • A: Alpha mask
  • RGBA: RGB with alpha channel (The actual order of channels is most often BGR!)
  • XYZA: XYZ with alpha channel
  • LABA: LAB with alpha channel
  • CMYKA: CMYK with alpha channel
  • GRAYA: Gray with alpha channel
  • YCbCrA: YCbCr with alpha channel

colorDepth

A string describing the color depth of the image:

  • U8: unsigned 8 bits integer, the most common type
  • U16: unsigned 16 bits integer
  • F16: half, 16 bits floating point. Only available if Krita was built with OpenEXR
  • F32: 32 bits floating point

colorProfile

a valid color profile for this color model and color depth combination.

Return

(no description provided)

setInheritAlpha(value: bool)
Krita 4.0.0

set the Inherit Alpha flag to the given value

Parameters

value(no description provided)
setLayerStyleFromAsl(asl: str)bool
Krita 5.0.0

set a new layer style for this node.

Parameters

asl(no description provided)

Return

true if layer style was set, false if failed.

setLocked(value: bool)
Krita 4.0.0

set the Locked flag to the give value

Parameters

value(no description provided)
setName(name: str)
Krita 4.0.0

rename the Node to the given name

Parameters

name(no description provided)
setOpacity(value: int)
Krita 4.0.0

set the opacity of the Node to the given value. The opacity is a value between 0 and 255.

Parameters

value(no description provided)
setPinnedToTimeline(pinned: bool)
Krita 5.0.0

Sets whether or not node should be pinned to the Timeline Docker, regardless of selection activity.

Parameters

pinned(no description provided)
setPixelData(value: QByteArray, x: int, y: int, w: int, h: int)bool
Krita 4.0.0Krita 5.0.0

writes the given bytes, of which there must be enough, into the Node, if the Node has writable pixel data:

  • paint layer: the layer's original pixels are overwritten
  • filter layer, generator layer, any mask: the embedded selection's pixels are overwritten. Note: for these

File layers, Group layers, Clone layers cannot be written to. Calling setPixelData on those layer types will silently do nothing.

Parameters

value

the byte array representing the pixels. There must be enough bytes available. Krita will take the raw pointer from the QByteArray and start reading, not stopping before (number of channels * size of channel * w * h) bytes are read.

x

the x position to start writing from

y

the y position to start writing from

w

the width of each row

h

the number of rows to write

Return

true if writing the pixeldata worked

setShowInTimeline(showInTimeline: bool)
Krita 4.2.0

Should the node be visible in the timeline. It defaults to false with new layer

Parameters

showInTimeline(no description provided)
setVisible(visible: bool)
Krita 4.0.0

Set the visibility of the current node to visible

Parameters

visible

(no description provided)

shearNode(angleX: float, angleY: float)
Krita 4.0.0

perform a shear operation on this node.

Parameters

angleX

the X-angle in degrees to shear by

angleY

the Y-angle in degrees to shear by

showInTimeline()bool
Krita 4.2.0

Return

is layer is shown in the timeline

thumbnail(w: int, h: int)QImage
Krita 4.0.0

create a thumbnail of the given dimensions. The thumbnail is sized according to the layer dimensions, not the image dimensions. If the requested size is too big a null QImage is created. If the current node cannot generate a thumbnail, a transparent QImage of the requested size is generated.

Parameters

w(no description provided)
h(no description provided)

Return

a QImage representing the layer contents.

type()str
Krita 4.0.0

Krita has several types of nodes, split in layers and masks. Group layers can contain other layers, any layer can contain masks.

Return

The type of the node. Valid types are:

  • paintlayer

  • grouplayer

  • filelayer

  • filterlayer

  • filllayer

  • clonelayer

  • vectorlayer

  • transparencymask

  • filtermask

  • transformmask

  • selectionmask

  • colorizemask

If the Node object isn't wrapping a valid Krita layer or mask object, and empty string is returned.

uniqueId()QUuid
Krita 4.4.5Krita 5.0.0

uniqueId of the node

Return

a QUuid representing a unique id to identify the node

visible()bool
Krita 4.0.0

Check whether the current Node is visible in the layer stack

Return

(no description provided)