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(device?: QWidget | QImage): QPainter

Overrides Component.constructor

Parameters:

NameType
device?QWidget | QImage

Returns: QPainter

Properties

native

• native: NativeElement | null

Inherited from Component.native

Methods

begin

â–¸ begin(device: QWidget | QImage): boolean

Parameters:

NameType
deviceQWidget | QImage

Returns: boolean


beginNativePainting

â–¸ beginNativePainting(): void

Returns: void


boundingRect

â–¸ boundingRect(x: number, y: number, w: number, h: number, flags: number, text: string): QRect

Parameters:

NameType
xnumber
ynumber
wnumber
hnumber
flagsnumber
textstring

Returns: QRect


boundingRectF

â–¸ boundingRectF(x: number, y: number, w: number, h: number, flags: number, text: string): QRect

Version of boundingRect() which takes floating point parameters.

Parameters:

NameType
xnumber
ynumber
wnumber
hnumber
flagsnumber
textstring

Returns: QRect


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


drawArcF

â–¸ drawArcF(x: number, y: number, width: number, height: number, startAngle: number, spanAngle: number): void

Version of drawArc() which takes floating point parameters.

Parameters:

NameType
xnumber
ynumber
widthnumber
heightnumber
startAnglenumber
spanAnglenumber

Returns: void


drawChord

â–¸ drawChord(x: number, y: number, width: number, height: number, startAngle: number, spanAngle: number): void

Parameters:

NameType
xnumber
ynumber
widthnumber
heightnumber
startAnglenumber
spanAnglenumber

Returns: void


drawChordF

â–¸ drawChordF(x: number, y: number, width: number, height: number, startAngle: number, spanAngle: number): void

Version of drawChord() which takes floating point parameters.

Parameters:

NameType
xnumber
ynumber
widthnumber
heightnumber
startAnglenumber
spanAnglenumber

Returns: void


drawConvexPolygon

â–¸ drawConvexPolygon(points: QPoint[]): void

Parameters:

NameType
pointsQPoint[]

Returns: void


drawConvexPolygonF

â–¸ drawConvexPolygonF(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


drawEllipseF

â–¸ drawEllipseF(x: number, y: number, width: number, height: number): void

Version of drawEllipse() which takes floating point parameters.

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


drawImageF

â–¸ drawImageF(x: number, y: number, image: QImage, sx: number, sy: number, sw: number, sh: number): void

Version of drawImage() which takes floating point parameters.

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


drawLineF

â–¸ drawLineF(x1: number, y1: number, x2: number, y2: number): void

Version of drawLine() which takes floating point parameters.

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


drawPieF

â–¸ drawPieF(x: number, y: number, width: number, height: number, startAngle: number, sweepLength: number): void

Version of drawPie() which takes floating point parameters.

Parameters:

NameType
xnumber
ynumber
widthnumber
heightnumber
startAnglenumber
sweepLengthnumber

Returns: void


drawPixmap

â–¸ drawPixmap(x: number, y: number, pixmap: QPixmap, sx: number, sy: number, sw: number, sh: number): void

Parameters:

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

Returns: void


drawPoint

â–¸ drawPoint(x: number, y: number): void

Parameters:

NameType
xnumber
ynumber

Returns: void


drawPointF

â–¸ drawPointF(x: number, y: number): void

Parameters:

NameType
xnumber
ynumber

Returns: void


drawRect

â–¸ drawRect(x: number, y: number, width: number, height: number): void

Parameters:

NameType
xnumber
ynumber
widthnumber
heightnumber

Returns: void


drawRectF

â–¸ drawRectF(x: number, y: number, width: number, height: number): void

Version of drawRect() which takes floating point parameters.

Parameters:

NameType
xnumber
ynumber
widthnumber
heightnumber

Returns: void


drawText

â–¸ drawText(x: number, y: number, text: string): void

Parameters:

NameType
xnumber
ynumber
textstring

Returns: void


drawTextF

â–¸ drawTextF(x: number, y: number, text: string): void

Version of drawText() which takes floating point parameters

Parameters:

NameType
xnumber
ynumber
textstring

Returns: void


end

â–¸ end(): boolean

Returns: boolean


endNativePainting

â–¸ endNativePainting(): void

Returns: void


eraseRect

â–¸ eraseRect(x: number, y: number, width: number, height: number): void

Parameters:

NameType
xnumber
ynumber
widthnumber
heightnumber

Returns: void


eraseRectF

â–¸ eraseRectF(x: number, y: number, width: number, height: number): void

Version of eraseRect() which takes floating point parameters.

Parameters:

NameType
xnumber
ynumber
widthnumber
heightnumber

Returns: void


fillRect

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

Parameters:

NameType
xnumber
ynumber
widthnumber
heightnumber
colorQColor

Returns: void


fillRectF

â–¸ fillRectF(x: number, y: number, width: number, height: number, color: QColor): void

Version of fillRect() which takes floating point parameters.

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(colorOrBrush: QColor | QBrush): void

Parameters:

NameType
colorOrBrushQColor | QBrush

Returns: void


setBrushOrigin

â–¸ setBrushOrigin(x: number, y: number): void

Parameters:

NameType
xnumber
ynumber

Returns: void


setBrushOriginF

â–¸ setBrushOriginF(x: number, y: number): void

Version of setBrushOrigin() which takes floating point parameters.

Parameters:

NameType
xnumber
ynumber

Returns: void


setCompositionMode

â–¸ setCompositionMode(mode: CompositionMode): void

Parameters:

NameType
modeCompositionMode

Returns: void


setFont

â–¸ setFont(font: QFont): void

Parameters:

NameType
fontQFont

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