Skip to main content

LensStudio:Ui.Widget

Class

Base class for all UI widgets.

Index

Example

const root = new Widget(parent);
const layout = new BoxLayout();
layout.setDirection(Direction.TopToBottom);
layout.spacing = 8;
root.layout = layout;

const title = new Label(root);
title.text = 'Widget Base Class';
title.fontRole = FontRole.LargeTitleBold;
layout.addWidget(title);

// Widget with custom size and margins
const box = new Widget(root);
box.setFixedHeight(60);
box.setContentsMargins(12, 8, 12, 8);
box.autoFillBackground = true;
(box as any).backgroundRole = BackgroundRole.ComponentBackground;

const boxLayout = new BoxLayout();
boxLayout.setDirection(Direction.TopToBottom);
box.layout = boxLayout;

const boxLabel = new Label(box);
boxLabel.text = 'Custom background + fixed height';
boxLayout.addWidget(boxLabel);

layout.addWidget(box);

// Show resize signal
const sizeLabel = new Label(root);
sizeLabel.text = `Size: ${root.width} x ${root.height}`;
sizeLabel.fontRole = FontRole.Small;
layout.addWidget(sizeLabel);

this.connections.push(
root.onResize.connect((w: number, h: number) => {
sizeLabel.text = `Size: ${w} x ${h}`;
})
);

Extends

Extended by

Constructors

Constructor

new Widget(parent): Widget

Constructs a new Widget with the given parent widget.

Parameters

ParameterType
parentWidget

Returns

Widget

Overrides

QtObject.constructor

Properties

autoFillBackground

autoFillBackground: boolean

Whether the widget automatically fills its background before painting.


backgroundRole

backgroundRole: ColorRole

The color role used for the widget's background.


className

readonly className: string

Class name of the underlying widget type.


contextMenuPolicy

contextMenuPolicy: ContextMenuPolicy

Controls how the widget handles context menu requests.


devicePixelRatio

readonly devicePixelRatio: number

The ratio between physical and logical pixels for the widget's display.


enabled

enabled: boolean

Whether the widget is interactive and accepts user input.


fontRole

fontRole: FontRole

The font role applied to the widget's text rendering.


foregroundRole

foregroundRole: ColorRole

The color role used for the widget's foreground elements.


hasFocus

readonly hasFocus: boolean

True when the widget currently holds keyboard focus.


height

readonly height: number

Current height of the widget in pixels.


hidden

hidden: boolean

Whether the widget is hidden from view.


isNull

readonly isNull: boolean

True if the underlying native widget object has been destroyed.


isTransparentForMouseEvents

isTransparentForMouseEvents: boolean

When true, mouse events pass through the widget to widgets below.


layout

layout: Layout

The layout manager assigned to arrange child widgets.


objectName

objectName: string

Identifier by which the widget can be located via findChild.


onClose

readonly onClose: signal1<CloseEvent, void>

Signal emitted when the widget is closed.


onFocusIn

readonly onFocusIn: signal0<void>

Emitted when the widget gains keyboard focus.


onFocusOut

readonly onFocusOut: signal0<void>

Emitted when the widget loses keyboard focus.


onHide

readonly onHide: signal0<void>

Signal emitted when the widget becomes hidden.


onKeyPress

readonly onKeyPress: signal1<number, void>

Signal emitted when a key is pressed while the widget has focus.


onMouseDoubleClick

readonly onMouseDoubleClick: signal1<MouseEvent, void>

Signal emitted when the user double-clicks on the widget.


onMouseMove

readonly onMouseMove: signal1<MouseEvent, void>

Signal emitted when the mouse moves over the widget.


onMousePress

readonly onMousePress: signal1<MouseEvent, void>

Signal emitted when a mouse button is pressed on the widget.


onMouseRelease

readonly onMouseRelease: signal1<MouseEvent, void>

Signal emitted when a mouse button is released on the widget.


onResize

readonly onResize: signal2<number, number, void>

Signal emitted when the widget is resized.


onShow

readonly onShow: signal0<void>

Signal emitted when the widget becomes visible.


toolTip

toolTip: string

Text displayed in a tooltip when the user hovers over the widget.


visible

visible: boolean

Whether the widget is currently visible.


width

readonly width: number

Current width of the widget in pixels.


windowTitle

windowTitle: string

Title text displayed in the widget's title bar when shown as a window.

Methods

actions()

actions(): Action[]

Returns

Action[]


activateWindow()

activateWindow(): void

Brings the widget's top-level window to the foreground and gives it focus.

Returns

void


adjustSize()

adjustSize(): void

Resizes the widget to fit its contents based on the size hint.

Returns

void


blockSignals()

blockSignals(blocked): void

Blocks or unblocks signal emission from the widget.

Parameters

ParameterType
blockedboolean

Returns

void


close()

close(): void

Closes the widget, hiding it and emitting the onClose signal.

Returns

void


deleteLater()

deleteLater(): void

Schedules the widget for deletion after the current event loop iteration.

Returns

void


findChild()

findChild(objectName): Widget

Returns the descendant widget with the given object name, or null if none matches.

Parameters

ParameterType
objectNamestring

Returns

Widget


getProperty()

getProperty(name): any

Returns the value of the dynamic property with the given name.

Parameters

ParameterType
namestring

Returns

any


getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

QtObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

QtObject.getTypeName


grab()

grab(): Pixmap

Captures the widget's current rendered content as a Pixmap.

Returns

Pixmap


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

QtObject.isOfType


isSame()

isSame(other): boolean

Returns true if this object refers to the same instance as the given object.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

QtObject.isSame


mapToGlobal()

mapToGlobal(x, y): Point

Parameters

ParameterType
xnumber
ynumber

Returns

Point


move()

move(ax, ay): void

Moves the widget to the specified position.

Parameters

ParameterType
axnumber
aynumber

Returns

void


raise()

raise(): void

Raises the widget to the top of the parent widget's stack.

Returns

void


resize()

resize(width, height): void

Resizes the widget to the specified width and height.

Parameters

ParameterType
widthnumber
heightnumber

Returns

void


setContentsMargins()

setContentsMargins(left, top, right, bottom): void

Sets the margins around the widget's contents.

Parameters

ParameterType
leftnumber
topnumber
rightnumber
bottomnumber

Returns

void


setCursor()

setCursor(shape): void

Sets the cursor shape displayed when the mouse is over the widget.

Parameters

ParameterType
shapeCursorShape

Returns

void


setCursorPixmap()

setCursorPixmap(pixmap): void

Sets a custom pixmap as the cursor when the mouse is over the widget.

Parameters

ParameterType
pixmapPixmap

Returns

void


setFixedHeight()

setFixedHeight(height): void

Locks the widget's height to the given value, preventing resizing.

Parameters

ParameterType
heightnumber

Returns

void


setFixedWidth()

setFixedWidth(width): void

Locks the widget's width to the given value, preventing resizing.

Parameters

ParameterType
widthnumber

Returns

void


setFocus()

setFocus(): void

Gives keyboard input focus to the widget.

Returns

void


setMaximumHeight()

setMaximumHeight(height): void

Sets the maximum height the widget can be resized to.

Parameters

ParameterType
heightnumber

Returns

void


setMaximumWidth()

setMaximumWidth(width): void

Sets the maximum width the widget can be resized to.

Parameters

ParameterType
widthnumber

Returns

void


setMinimumHeight()

setMinimumHeight(height): void

Sets the minimum height the widget must maintain.

Parameters

ParameterType
heightnumber

Returns

void


setMinimumWidth()

setMinimumWidth(width): void

Sets the minimum width the widget must maintain.

Parameters

ParameterType
widthnumber

Returns

void


setProperty()

setProperty(name, value): boolean

Sets the dynamic property with the given name to the given value.

Parameters

ParameterType
namestring
valueany

Returns

boolean


setSizePolicy()

setSizePolicy(horizontal, vertical): void

Controls how the widget grows or shrinks relative to its layout.

Parameters

ParameterType
horizontalPolicy
verticalPolicy

Returns

void


setUndoable()

setUndoable(undoable): void

Marks property changes on this widget as undoable via the undo stack.

Parameters

ParameterType
undoableboolean

Returns

void


setUndoableRecursive()

setUndoableRecursive(undoable): void

Marks property changes on this widget and all its children as undoable.

Parameters

ParameterType
undoableboolean

Returns

void


show()

show(): void

Makes the widget visible.

Returns

void


unsetCursor()

unsetCursor(): void

Resets the cursor to the parent widget's cursor.

Returns

void