Skip to main content

LensStudio:Ui.ColorButton

Class

Button for selecting or displaying a color.

Index

Example

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

const status = new Label(root);
status.text = 'Pick a color:';
status.fontRole = FontRole.Title;
layout.addWidget(status);

// ColorButton opens a color picker on click
const colorBtn = new ColorButton(root);
colorBtn.alphaEnabled = true;
layout.addWidget(colorBtn);

// React to color changes during selection
const conn = colorBtn.colorValueChanged.connect((color) => {
status.text = `R:${color.red.toFixed(2)} G:${color.green.toFixed(2)} B:${color.blue.toFixed(2)} A:${color.alpha.toFixed(2)}`;
console.log('Color changed:', color.red, color.green, color.blue, color.alpha);
});
this.connections.push(conn);

console.log('alphaEnabled:', colorBtn.alphaEnabled);

Extends

Constructors

Constructor

new ColorButton(parent): ColorButton

Constructor for ColorButton widget.

Parameters

ParameterType
parentWidget

Returns

ColorButton

Overrides

PushButton.constructor

Properties

alphaEnabled

alphaEnabled: boolean

Whether the alpha channel is enabled in the color picker.


autoFillBackground

autoFillBackground: boolean

Whether the widget automatically fills its background before painting.

Inherited from

PushButton.autoFillBackground


backgroundRole

backgroundRole: ColorRole

The color role used for the widget's background.

Inherited from

PushButton.backgroundRole


checkable

checkable: boolean

Whether the button is checkable (toggleable).

Inherited from

PushButton.checkable


checked

checked: boolean

Current checked state of the button.

Inherited from

PushButton.checked


className

readonly className: string

Class name of the underlying widget type.

Inherited from

PushButton.className


colorAccepted

readonly colorAccepted: signal1<Color, void>

Emitted when a color is accepted in the picker.


colorRejected

readonly colorRejected: signal1<Color, void>

Emitted when the color picker is closed without accepting.


colorValueChanged

readonly colorValueChanged: signal1<Color, void>

Emitted when the color value changes during selection.


contextMenuPolicy

contextMenuPolicy: ContextMenuPolicy

Controls how the widget handles context menu requests.

Inherited from

PushButton.contextMenuPolicy


currentColor

currentColor: Color

The currently displayed color in the button.


devicePixelRatio

readonly devicePixelRatio: number

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

Inherited from

PushButton.devicePixelRatio


dialogClosed

readonly dialogClosed: signal0<void>

Emitted when the color picker dialog is closed.


dialogCreated

readonly dialogCreated: signal1<Color, void>

Emitted when the color picker dialog is created.


enabled

enabled: boolean

Whether the widget is interactive and accepts user input.

Inherited from

PushButton.enabled


fontRole

fontRole: FontRole

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

Inherited from

PushButton.fontRole


foregroundRole

foregroundRole: ColorRole

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

Inherited from

PushButton.foregroundRole


hasFocus

readonly hasFocus: boolean

True when the widget currently holds keyboard focus.

Inherited from

PushButton.hasFocus


height

readonly height: number

Current height of the widget in pixels.

Inherited from

PushButton.height


hidden

hidden: boolean

Whether the widget is hidden from view.

Inherited from

PushButton.hidden


isDialogActive

readonly isDialogActive: boolean

Whether the color picker dialog is currently open.


isNull

readonly isNull: boolean

True if the underlying native widget object has been destroyed.

Inherited from

PushButton.isNull


isTransparentForMouseEvents

isTransparentForMouseEvents: boolean

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

Inherited from

PushButton.isTransparentForMouseEvents


lastAcceptedColor

readonly lastAcceptedColor: Color

The last color value that was accepted by the user.


layout

layout: Layout

The layout manager assigned to arrange child widgets.

Inherited from

PushButton.layout


objectName

objectName: string

Identifier by which the widget can be located via findChild.

Inherited from

PushButton.objectName


onClick

readonly onClick: signal0<void>

Signal emitted when the button is clicked.

Inherited from

PushButton.onClick


onClose

readonly onClose: signal1<CloseEvent, void>

Signal emitted when the widget is closed.

Inherited from

PushButton.onClose


onFocusIn

readonly onFocusIn: signal0<void>

Emitted when the widget gains keyboard focus.

Inherited from

PushButton.onFocusIn


onFocusOut

readonly onFocusOut: signal0<void>

Emitted when the widget loses keyboard focus.

Inherited from

PushButton.onFocusOut


onHide

readonly onHide: signal0<void>

Signal emitted when the widget becomes hidden.

Inherited from

PushButton.onHide


onKeyPress

readonly onKeyPress: signal1<number, void>

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

Inherited from

PushButton.onKeyPress


onMouseDoubleClick

readonly onMouseDoubleClick: signal1<MouseEvent, void>

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

Inherited from

PushButton.onMouseDoubleClick


onMouseMove

readonly onMouseMove: signal1<MouseEvent, void>

Signal emitted when the mouse moves over the widget.

Inherited from

PushButton.onMouseMove


onMousePress

readonly onMousePress: signal1<MouseEvent, void>

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

Inherited from

PushButton.onMousePress


onMouseRelease

readonly onMouseRelease: signal1<MouseEvent, void>

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

Inherited from

PushButton.onMouseRelease


onResize

readonly onResize: signal2<number, number, void>

Signal emitted when the widget is resized.

Inherited from

PushButton.onResize


onShow

readonly onShow: signal0<void>

Signal emitted when the widget becomes visible.

Inherited from

PushButton.onShow


primary

primary: boolean

Whether the button is styled as a primary action button.

Inherited from

PushButton.primary


text

text: string

The button's display text.

Inherited from

PushButton.text


toolTip

toolTip: string

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

Inherited from

PushButton.toolTip


visible

visible: boolean

Whether the widget is currently visible.

Inherited from

PushButton.visible


width

readonly width: number

Current width of the widget in pixels.

Inherited from

PushButton.width


windowTitle

windowTitle: string

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

Inherited from

PushButton.windowTitle

Methods

actions()

actions(): Action[]

Returns

Action[]

Inherited from

PushButton.actions


activateWindow()

activateWindow(): void

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

Returns

void

Inherited from

PushButton.activateWindow


adjustSize()

adjustSize(): void

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

Returns

void

Inherited from

PushButton.adjustSize


blockSignals()

blockSignals(blocked): void

Blocks or unblocks signal emission from the widget.

Parameters

ParameterType
blockedboolean

Returns

void

Inherited from

PushButton.blockSignals


close()

close(): void

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

Returns

void

Inherited from

PushButton.close


deleteLater()

deleteLater(): void

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

Returns

void

Inherited from

PushButton.deleteLater


findChild()

findChild(objectName): Widget

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

Parameters

ParameterType
objectNamestring

Returns

Widget

Inherited from

PushButton.findChild


getProperty()

getProperty(name): any

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

Parameters

ParameterType
namestring

Returns

any

Inherited from

PushButton.getProperty


getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

PushButton.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

PushButton.getTypeName


grab()

grab(): Pixmap

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

Returns

Pixmap

Inherited from

PushButton.grab


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

PushButton.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

PushButton.isSame


mapToGlobal()

mapToGlobal(x, y): Point

Parameters

ParameterType
xnumber
ynumber

Returns

Point

Inherited from

PushButton.mapToGlobal


move()

move(ax, ay): void

Moves the widget to the specified position.

Parameters

ParameterType
axnumber
aynumber

Returns

void

Inherited from

PushButton.move


raise()

raise(): void

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

Returns

void

Inherited from

PushButton.raise


resize()

resize(width, height): void

Resizes the widget to the specified width and height.

Parameters

ParameterType
widthnumber
heightnumber

Returns

void

Inherited from

PushButton.resize


setAutoUpdateToolTip()

setAutoUpdateToolTip(autoUpdateToolTip): void

Update the tooltip automatically based on current state.

Parameters

ParameterType
autoUpdateToolTipboolean

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

Inherited from

PushButton.setContentsMargins


setCursor()

setCursor(shape): void

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

Parameters

ParameterType
shapeCursorShape

Returns

void

Inherited from

PushButton.setCursor


setCursorPixmap()

setCursorPixmap(pixmap): void

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

Parameters

ParameterType
pixmapPixmap

Returns

void

Inherited from

PushButton.setCursorPixmap


setFixedHeight()

setFixedHeight(height): void

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

Parameters

ParameterType
heightnumber

Returns

void

Inherited from

PushButton.setFixedHeight


setFixedWidth()

setFixedWidth(width): void

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

Parameters

ParameterType
widthnumber

Returns

void

Inherited from

PushButton.setFixedWidth


setFocus()

setFocus(): void

Gives keyboard input focus to the widget.

Returns

void

Inherited from

PushButton.setFocus


setIcon()

setIcon(icon): void

Set the button's icon.

Parameters

ParameterType
iconIcon

Returns

void

Inherited from

PushButton.setIcon


setIconMode()

setIconMode(iconMode): void

Sets the icon display mode for the button.

Parameters

ParameterType
iconModeIconMode

Returns

void

Inherited from

PushButton.setIconMode


setIconSize()

setIconSize(w, h): void

Set the button's icon dimensions.

Parameters

ParameterType
wnumber
hnumber

Returns

void

Inherited from

PushButton.setIconSize


setIconWithMode()

setIconWithMode(icon, iconMode): void

Sets the button icon and its display mode simultaneously.

Parameters

ParameterType
iconIcon
iconModeIconMode

Returns

void

Inherited from

PushButton.setIconWithMode


setMaximumHeight()

setMaximumHeight(height): void

Sets the maximum height the widget can be resized to.

Parameters

ParameterType
heightnumber

Returns

void

Inherited from

PushButton.setMaximumHeight


setMaximumWidth()

setMaximumWidth(width): void

Sets the maximum width the widget can be resized to.

Parameters

ParameterType
widthnumber

Returns

void

Inherited from

PushButton.setMaximumWidth


setMinimumHeight()

setMinimumHeight(height): void

Sets the minimum height the widget must maintain.

Parameters

ParameterType
heightnumber

Returns

void

Inherited from

PushButton.setMinimumHeight


setMinimumWidth()

setMinimumWidth(width): void

Sets the minimum width the widget must maintain.

Parameters

ParameterType
widthnumber

Returns

void

Inherited from

PushButton.setMinimumWidth


setProperty()

setProperty(name, value): boolean

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

Parameters

ParameterType
namestring
valueany

Returns

boolean

Inherited from

PushButton.setProperty


setSizePolicy()

setSizePolicy(horizontal, vertical): void

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

Parameters

ParameterType
horizontalPolicy
verticalPolicy

Returns

void

Inherited from

PushButton.setSizePolicy


setUndoable()

setUndoable(undoable): void

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

Parameters

ParameterType
undoableboolean

Returns

void

Inherited from

PushButton.setUndoable


setUndoableRecursive()

setUndoableRecursive(undoable): void

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

Parameters

ParameterType
undoableboolean

Returns

void

Inherited from

PushButton.setUndoableRecursive


show()

show(): void

Makes the widget visible.

Returns

void

Inherited from

PushButton.show


unsetCursor()

unsetCursor(): void

Resets the cursor to the parent widget's cursor.

Returns

void

Inherited from

PushButton.unsetCursor