QPainter

Lets you paint on widgets.

This class is a JS wrapper around Qt's QPainter class

Note: QPainter works only inside the paint event.

Example

import { FlexLayout, WidgetEventTypes, QMainWindow, QPainter, QWidget } from '@nodegui/nodegui';
const win = new QMainWindow();
const center = new QWidget();
const layout = new FlexLayout();
center.setLayout(layout);
win.resize(200, 200);
win.addEventListener(WidgetEventTypes.Paint, () => {
const painter = new QPainter(win);
painter.drawText(20, 20, 'Hello');
painter.end();
});
win.show();
(global as any).win = win;

Advanced example:

https://github.com/nodegui/examples/blob/master/nodegui/custom-native-widget-qpainter

Hierarchy

Index

Constructors

Properties

Methods

Constructors

constructor

+ new QPainter(): QPainter

Overrides Component.constructor

Returns: QPainter

+ new QPainter(device: Component): QPainter

Overrides Component.constructor

Parameters:

NameType
deviceComponent

Returns: QPainter

Properties

native

native: NativeElement

Overrides Component.native


nodeChildren

nodeChildren: Set‹Component

Inherited from Component.nodeChildren


Optional nodeParent

nodeParent? : Component

Inherited from Component.nodeParent

Methods

begin

begin(device: QWidget | QImage): boolean

Parameters:

NameType
deviceQWidget | QImage

Returns: boolean


beginNativePainting

beginNativePainting(): void

Returns: void


compositionMode

compositionMode(): CompositionMode

Returns: CompositionMode


drawArc

drawArc(x: number, y: number, width: number, height: number, startAngle: number, spanAngle: number): void

Parameters:

NameType
xnumber
ynumber
widthnumber
heightnumber
startAnglenumber
spanAnglenumber

Returns: void


drawConvexPolygon

drawConvexPolygon(points: QPoint[]): void

Parameters:

NameType
pointsQPoint[]

Returns: void


drawEllipse

drawEllipse(x: number, y: number, width: number, height: number): void

Parameters:

NameType
xnumber
ynumber
widthnumber
heightnumber

Returns: void


drawImage

drawImage(x: number, y: number, image: QImage, sx: number, sy: number, sw: number, sh: number): void

Parameters:

NameTypeDefault
xnumber-
ynumber-
imageQImage-
sxnumber0
synumber0
swnumber-1
shnumber-1

Returns: void


drawLine

drawLine(x1: number, y1: number, x2: number, y2: number): void

Parameters:

NameType
x1number
y1number
x2number
y2number

Returns: void


drawPath

drawPath(path: QPainterPath): void

Parameters:

NameType
pathQPainterPath

Returns: void


drawPie

drawPie(x: number, y: number, width: number, height: number, startAngle: number, sweepLength: number): void

Parameters:

NameType
xnumber
ynumber
widthnumber
heightnumber
startAnglenumber
sweepLengthnumber

Returns: void


drawText

drawText(x: number, y: number, text: string): void

Parameters:

NameType
xnumber
ynumber
textstring

Returns: void


end

end(): boolean

Returns: boolean


endNativePainting

endNativePainting(): void

Returns: void


fillRect

fillRect(x: number, y: number, width: number, height: number, color: QColor): void

Parameters:

NameType
xnumber
ynumber
widthnumber
heightnumber
colorQColor

Returns: void


opacity

opacity(): number

Returns: number


restore

restore(): void

Returns: void


rotate

rotate(angle: number): void

Parameters:

NameType
anglenumber

Returns: void


save

save(): void

Returns: void


scale

scale(sx: number, sy: number): void

Parameters:

NameType
sxnumber
synumber

Returns: void


setBrush

setBrush(color: QColor): void

Parameters:

NameType
colorQColor

Returns: void


setCompositionMode

setCompositionMode(mode: CompositionMode): void

Parameters:

NameType
modeCompositionMode

Returns: void


setFont

setFont(font: QFont): void

Parameters:

NameType
fontQFont

Returns: void


setNodeParent

setNodeParent(parent?: Component): void

Inherited from Component.setNodeParent

Parameters:

NameType
parent?Component

Returns: void


setOpacity

setOpacity(opacity: number): void

Parameters:

NameType
opacitynumber

Returns: void


setPen

setPen(arg: PenStyle | QColor | QPen): void

Parameters:

NameType
argPenStyle | QColor | QPen

Returns: void


setRenderHint

setRenderHint(hint: RenderHint, on: boolean): void

Parameters:

NameTypeDefault
hintRenderHint-
onbooleantrue

Returns: void


setTransform

setTransform(matrix2x3: number[] | Float32Array, combine: boolean): void

Sets the world transformation matrix.

Parameters:

NameTypeDefaultDescription
matrix2x3number[] | Float32Array-An array of length 6 representing a 2x3 transformation matrix. The order of elements corresponds to the convention used in QTransform, i.e. m11, m12, m21, m22, dx, and dy.
combinebooleanfalseIf set then this transform will be combining with the curent one. Otherwise it replaces it completely.

Returns: void


strokePath

strokePath(path: QPainterPath, pen: QPen): void

Parameters:

NameType
pathQPainterPath
penQPen

Returns: void


translate

translate(dx: number, dy: number): void

Parameters:

NameType
dxnumber
dynumber

Returns: void