Class Selection
Build from Selection.h
Krita 4.0.0Krita 4.3.0

Selection represents a selection on Krita. A selection is not necessarily associated with a particular Node or Image.

from krita import *d = Application.activeDocument()n = d.activeNode()r = n.bounds() s = Selection()s.select(r.width() / 3, r.height() / 3, r.width() / 3, r.height() / 3, 255)s.cut(n)

Methods

add(selection: Selection) border(xRadius: int, yRadius: int) clear() contract(value: int) copy(node: Node) cut(node: Node) dilate() duplicate() erode() feather(radius: int) grow(xradius: int, yradius: int) height()int intersect(selection: Selection) invert() move(x: int, y: int) paste(destination: Node, x: int, y: int) pixelData(x: int, y: int, w: int, h: int)QByteArray replace(selection: Selection) resize(w: int, h: int) select(x: int, y: int, w: int, h: int, value: int) selectAll(node: Node, value: int) setPixelData(value: QByteArray, x: int, y: int, w: int, h: int) shrink(xRadius: int, yRadius: int, edgeLock: bool) smooth() subtract(selection: Selection) symmetricdifference(selection: Selection) width()int x()int y()int

Member documentation

add(selection: Selection)
Krita 4.0.0

Add the given selection's selected pixels to the current selection.

Parameters

selection(no description provided)
border(xRadius: int, yRadius: int)
Krita 4.0.0

Border the selection with the given radius.

Parameters

xRadius(no description provided)
yRadius(no description provided)
clear()
Krita 4.0.0

Make the selection entirely unselected.

contract(value: int)
Krita 4.0.0

Make the selection's width and height smaller by the given value. This will not move the selection's top-left position.

Parameters

value(no description provided)
copy(node: Node)
Krita 4.0.0

copies the area defined by the selection from the node to the clipboard.

Parameters

node

the node from where the pixels will be copied.

cut(node: Node)
Krita 4.0.0

erases the area defined by the selection from the node and puts a copy on the clipboard.

Parameters

node

the node from which the selection will be cut.

dilate()
Krita 4.0.0

Dilate the selection with a radius of 1 pixel.

Krita 4.3.0Krita 5.0.0

Return

a duplicate of the selection

erode()
Krita 4.0.0

Erode the selection with a radius of 1 pixel.

feather(radius: int)
Krita 4.0.0

Feather the selection with the given radius.

Parameters

radius(no description provided)
grow(xradius: int, yradius: int)
Krita 4.0.0

Grow the selection with the given radius.

Parameters

xradius(no description provided)
yradius(no description provided)
height()int
Krita 4.0.0

Return

the height of the selection

intersect(selection: Selection)
Krita 4.0.0

Intersect the given selection with this selection.

Parameters

selection(no description provided)
invert()
Krita 4.0.0

Invert the selection.

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

Move the selection's top-left corner to the given coordinates.

Parameters

x(no description provided)
y(no description provided)
paste(destination: Node, x: int, y: int)
Krita 4.0.0

pastes the content of the clipboard to the given node, limited by the area of the current selection.

Parameters

destination

the node where the pixels will be written

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

reads the given rectangle from the Selection's mask and returns it as a byte array. The pixel data starts top-left, and is ordered row-first.

The byte array will contain one byte for every pixel, representing the selectedness. 0 is totally unselected, 255 is fully selected.

You can read outside the Selection's boundaries; those pixels will be unselected.

The byte array is a copy of the original selection data.

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.

replace(selection: Selection)
Krita 4.0.0

Replace the current selection's selection with the one of the given selection.

Parameters

selection(no description provided)
resize(w: int, h: int)
Krita 4.0.0

Resize the selection to the given width and height. The top-left position will not be moved.

Parameters

w(no description provided)
h(no description provided)
select(x: int, y: int, w: int, h: int, value: int)
Krita 4.0.0

Select the given area. The value can be between 0 and 255; 0 is

totally unselected, 255 is totally selected.

Parameters

x(no description provided)
y(no description provided)
w(no description provided)
h(no description provided)
value(no description provided)
selectAll(node: Node, value: int)
Krita 4.0.0

Select all pixels in the given node. The value can be between 0 and 255; 0 is

totally unselected, 255 is totally selected.

Parameters

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

writes the given bytes, of which there must be enough, into the Selection.

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 (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

shrink(xRadius: int, yRadius: int, edgeLock: bool)
Krita 4.0.0

Shrink the selection with the given radius.

Parameters

xRadius(no description provided)
yRadius(no description provided)
edgeLock(no description provided)
smooth()
Krita 4.0.0

Smooth the selection.

subtract(selection: Selection)
Krita 4.0.0

Subtract the given selection's selected pixels from the current selection.

Parameters

selection(no description provided)
Krita 4.2.0

Intersect with the inverse of the given selection with this selection.

Parameters

selection(no description provided)
width()int
Krita 4.0.0

Return

the width of the selection

x()int
Krita 4.0.0

Return

the left-hand position of the selection.

y()int
Krita 4.0.0

Return

the top position of the selection.