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
-
↳ QPainter
Index
Constructors
Properties
Methods
- begin
- beginNativePainting
- boundingRect
- boundingRectF
- compositionMode
- drawArc
- drawArcF
- drawChord
- drawChordF
- drawConvexPolygon
- drawConvexPolygonF
- drawEllipse
- drawEllipseF
- drawImage
- drawImageF
- drawLine
- drawLineF
- drawPath
- drawPie
- drawPieF
- drawPixmap
- drawPoint
- drawPointF
- drawRect
- drawRectF
- drawRoundedRect
- drawRoundedRectF
- drawText
- drawTextF
- end
- endNativePainting
- eraseRect
- eraseRectF
- fillPath
- fillRect
- fillRectF
- opacity
- restore
- rotate
- save
- scale
- setBrush
- setBrushOrigin
- setBrushOriginF
- setCompositionMode
- setFont
- setOpacity
- setPen
- setRenderHint
- setTransform
- strokePath
- translate
Constructors
constructor
+ new QPainter(device?
: QWidget | QImage): QPainter
Overrides Component.constructor
Parameters:
Name | Type |
---|---|
device? | QWidget | QImage |
Returns: QPainter
Properties
native
• native: NativeElement | null
Inherited from Component.native
Methods
begin
▸ begin(device
: QWidget | QImage): boolean
Parameters:
Name | Type |
---|---|
device | QWidget | QImage |
Returns: boolean
beginNativePainting
▸ beginNativePainting(): void
Returns: void
boundingRect
▸ boundingRect(x
: number, y
: number, w
: number, h
: number, flags
: number, text
: string): QRect
Parameters:
Name | Type |
---|---|
x | number |
y | number |
w | number |
h | number |
flags | number |
text | string |
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:
Name | Type |
---|---|
x | number |
y | number |
w | number |
h | number |
flags | number |
text | string |
Returns: QRect
compositionMode
▸ compositionMode(): CompositionMode
Returns: CompositionMode
drawArc
▸ drawArc(x
: number, y
: number, width
: number, height
: number, startAngle
: number, spanAngle
: number): void
Parameters:
Name | Type |
---|---|
x | number |
y | number |
width | number |
height | number |
startAngle | number |
spanAngle | number |
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:
Name | Type |
---|---|
x | number |
y | number |
width | number |
height | number |
startAngle | number |
spanAngle | number |
Returns: void
drawChord
▸ drawChord(x
: number, y
: number, width
: number, height
: number, startAngle
: number, spanAngle
: number): void
Parameters:
Name | Type |
---|---|
x | number |
y | number |
width | number |
height | number |
startAngle | number |
spanAngle | number |
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:
Name | Type |
---|---|
x | number |
y | number |
width | number |
height | number |
startAngle | number |
spanAngle | number |
Returns: void
drawConvexPolygon
▸ drawConvexPolygon(points
: QPoint[]): void
Parameters:
Name | Type |
---|---|
points | QPoint[] |
Returns: void
drawConvexPolygonF
▸ drawConvexPolygonF(points
: QPoint[]): void
Parameters:
Name | Type |
---|---|
points | QPoint[] |
Returns: void
drawEllipse
▸ drawEllipse(x
: number, y
: number, width
: number, height
: number): void
Parameters:
Name | Type |
---|---|
x | number |
y | number |
width | number |
height | number |
Returns: void
drawEllipseF
▸ drawEllipseF(x
: number, y
: number, width
: number, height
: number): void
Version of drawEllipse() which takes floating point parameters.
Parameters:
Name | Type |
---|---|
x | number |
y | number |
width | number |
height | number |
Returns: void
drawImage
▸ drawImage(x
: number, y
: number, image
: QImage, sx
: number, sy
: number, sw
: number, sh
: number): void
Parameters:
Name | Type | Default |
---|---|---|
x | number | - |
y | number | - |
image | QImage | - |
sx | number | 0 |
sy | number | 0 |
sw | number | -1 |
sh | number | -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:
Name | Type | Default |
---|---|---|
x | number | - |
y | number | - |
image | QImage | - |
sx | number | 0 |
sy | number | 0 |
sw | number | -1 |
sh | number | -1 |
Returns: void
drawLine
▸ drawLine(x1
: number, y1
: number, x2
: number, y2
: number): void
Parameters:
Name | Type |
---|---|
x1 | number |
y1 | number |
x2 | number |
y2 | number |
Returns: void
drawLineF
▸ drawLineF(x1
: number, y1
: number, x2
: number, y2
: number): void
Version of drawLine() which takes floating point parameters.
Parameters:
Name | Type |
---|---|
x1 | number |
y1 | number |
x2 | number |
y2 | number |
Returns: void
drawPath
▸ drawPath(path
: QPainterPath): void
Parameters:
Name | Type |
---|---|
path | QPainterPath |
Returns: void
drawPie
▸ drawPie(x
: number, y
: number, width
: number, height
: number, startAngle
: number, sweepLength
: number): void
Parameters:
Name | Type |
---|---|
x | number |
y | number |
width | number |
height | number |
startAngle | number |
sweepLength | number |
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:
Name | Type |
---|---|
x | number |
y | number |
width | number |
height | number |
startAngle | number |
sweepLength | number |
Returns: void
drawPixmap
▸ drawPixmap(x
: number, y
: number, pixmap
: QPixmap, sx
: number, sy
: number, sw
: number, sh
: number): void
Parameters:
Name | Type | Default |
---|---|---|
x | number | - |
y | number | - |
pixmap | QPixmap | - |
sx | number | 0 |
sy | number | 0 |
sw | number | -1 |
sh | number | -1 |
Returns: void
drawPoint
▸ drawPoint(x
: number, y
: number): void
Parameters:
Name | Type |
---|---|
x | number |
y | number |
Returns: void
drawPointF
▸ drawPointF(x
: number, y
: number): void
Parameters:
Name | Type |
---|---|
x | number |
y | number |
Returns: void
drawRect
▸ drawRect(x
: number, y
: number, width
: number, height
: number): void
Parameters:
Name | Type |
---|---|
x | number |
y | number |
width | number |
height | number |
Returns: void
drawRectF
▸ drawRectF(x
: number, y
: number, width
: number, height
: number): void
Version of drawRect() which takes floating point parameters.
Parameters:
Name | Type |
---|---|
x | number |
y | number |
width | number |
height | number |
Returns: void
drawRoundedRect
▸ drawRoundedRect(x
: number, y
: number, w
: number, h
: number, xRadius
: number, yRadius
: number, mode
: SizeMode): void
Parameters:
Name | Type | Default |
---|---|---|
x | number | - |
y | number | - |
w | number | - |
h | number | - |
xRadius | number | - |
yRadius | number | - |
mode | SizeMode | SizeMode.AbsoluteSize |
Returns: void
drawRoundedRectF
▸ drawRoundedRectF(x
: number, y
: number, w
: number, h
: number, xRadius
: number, yRadius
: number, mode
: SizeMode): void
Parameters:
Name | Type | Default |
---|---|---|
x | number | - |
y | number | - |
w | number | - |
h | number | - |
xRadius | number | - |
yRadius | number | - |
mode | SizeMode | SizeMode.AbsoluteSize |
Returns: void
drawText
▸ drawText(x
: number, y
: number, text
: string): void
Parameters:
Name | Type |
---|---|
x | number |
y | number |
text | string |
Returns: void
drawTextF
▸ drawTextF(x
: number, y
: number, text
: string): void
Version of drawText() which takes floating point parameters
Parameters:
Name | Type |
---|---|
x | number |
y | number |
text | string |
Returns: void
end
▸ end(): boolean
Returns: boolean
endNativePainting
▸ endNativePainting(): void
Returns: void
eraseRect
▸ eraseRect(x
: number, y
: number, width
: number, height
: number): void
Parameters:
Name | Type |
---|---|
x | number |
y | number |
width | number |
height | number |
Returns: void
eraseRectF
▸ eraseRectF(x
: number, y
: number, width
: number, height
: number): void
Version of eraseRect() which takes floating point parameters.
Parameters:
Name | Type |
---|---|
x | number |
y | number |
width | number |
height | number |
Returns: void
fillPath
▸ fillPath(path
: QPainterPath, brush
: QBrush): void
Parameters:
Name | Type |
---|---|
path | QPainterPath |
brush | QBrush |
Returns: void
fillRect
▸ fillRect(x
: number, y
: number, width
: number, height
: number, color
: QColor): void
Parameters:
Name | Type |
---|---|
x | number |
y | number |
width | number |
height | number |
color | QColor |
Returns: void
fillRectF
▸ fillRectF(x
: number, y
: number, width
: number, height
: number, color
: QColor): void
Version of fillRect() which takes floating point parameters.
Parameters:
Name | Type |
---|---|
x | number |
y | number |
width | number |
height | number |
color | QColor |
Returns: void
opacity
▸ opacity(): number
Returns: number
restore
▸ restore(): void
Returns: void
rotate
▸ rotate(angle
: number): void
Parameters:
Name | Type |
---|---|
angle | number |
Returns: void
save
▸ save(): void
Returns: void
scale
▸ scale(sx
: number, sy
: number): void
Parameters:
Name | Type |
---|---|
sx | number |
sy | number |
Returns: void
setBrush
▸ setBrush(colorOrBrush
: QColor | QBrush): void
Parameters:
Name | Type |
---|---|
colorOrBrush | QColor | QBrush |
Returns: void
setBrushOrigin
▸ setBrushOrigin(x
: number, y
: number): void
Parameters:
Name | Type |
---|---|
x | number |
y | number |
Returns: void
setBrushOriginF
▸ setBrushOriginF(x
: number, y
: number): void
Version of setBrushOrigin() which takes floating point parameters.
Parameters:
Name | Type |
---|---|
x | number |
y | number |
Returns: void
setCompositionMode
▸ setCompositionMode(mode
: CompositionMode): void
Parameters:
Name | Type |
---|---|
mode | CompositionMode |
Returns: void
setFont
▸ setFont(font
: QFont): void
Parameters:
Name | Type |
---|---|
font | QFont |
Returns: void
setOpacity
▸ setOpacity(opacity
: number): void
Parameters:
Name | Type |
---|---|
opacity | number |
Returns: void
setPen
▸ setPen(arg
: PenStyle | QColor | QPen): void
Parameters:
Name | Type |
---|---|
arg | PenStyle | QColor | QPen |
Returns: void
setRenderHint
▸ setRenderHint(hint
: RenderHint, on
: boolean): void
Parameters:
Name | Type | Default |
---|---|---|
hint | RenderHint | - |
on | boolean | true |
Returns: void
setTransform
▸ setTransform(matrix2x3
: number[] | Float32Array, combine
: boolean): void
Sets the world transformation matrix.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
matrix2x3 | number[] | 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. |
combine | boolean | false | If 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:
Name | Type |
---|---|
path | QPainterPath |
pen | QPen |
Returns: void
translate
▸ translate(dx
: number, dy
: number): void
Parameters:
Name | Type |
---|---|
dx | number |
dy | number |
Returns: void