QWidget

Create and control views.

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

A QWidget can be used to encapsulate other widgets and provide structure. It functions similar to a div in the web world.

Example

const { QWidget } = require("@nodegui/nodegui");
const view = new QWidget();
view.setObjectName("container"); //Similar to setting `id` on the web
view.setLayout(new FlexLayout());

Type parameters

â–ª Signals: QWidgetSignals

Hierarchy

↳ YogaWidget‹Signals›

↳ QWidget

↳ QMenu

↳ QFrame

↳ QAbstractSlider

↳ QAbstractButton

↳ QAbstractSpinBox

↳ QCalendarWidget

↳ QDialog

↳ QLCDNumber

↳ QLineEdit

↳ QProgressBar

↳ QComboBox

↳ QTabBar

↳ QTabWidget

↳ QMenuBar

↳ QSvgWidget

↳ QGroupBox

↳ QStatusBar

↳ QMainWindow

Index

Constructors

Properties

Methods

Constructors

constructor

+ new QWidget(arg?: QWidget‹QWidgetSignals› | NativeElement): QWidget

Overrides QObject.constructor

Parameters:

NameType
arg?QWidget‹QWidgetSignals› | NativeElement

Returns: QWidget

Properties

_rawInlineStyle

• _rawInlineStyle: string


native

• native: NativeElement | null

Inherited from Component.native


type

• type: string

Methods

_id

â–¸ _id(): number

Inherited from QObject._id

Get an ID identifying the underlying C++ object.

This can be useful when debugging memory problems with help from setLogCreateQObject() and setLogDestroyQObject(). The number is hash of the memory address of the C++ object.

Returns: number

a unique number which is valid for the lifetime of the C++ object.


acceptDrops

â–¸ acceptDrops(): boolean

Returns: boolean


accessibleDescription

â–¸ accessibleDescription(): string

Returns: string


accessibleName

â–¸ accessibleName(): string

Returns: string


activateWindow

â–¸ activateWindow(): void

Returns: void


addAction

â–¸ addAction(action: QAction | string): QAction

Parameters:

NameType
actionQAction | string

Returns: QAction


addEventListener

▸ addEventListener‹SignalType›(signalType: SignalType, callback: Signals[SignalType], options?: EventListenerOptions): void

Inherited from EventWidget.addEventListener

Type parameters:

â–ª SignalType: keyof Signals

Parameters:

NameTypeDescription
signalTypeSignalTypeSignalType is a signal from the widgets signals interface.
callbackSignals[SignalType]Corresponding callback for the signal as mentioned in the widget's signal interface
options?EventListenerOptionsExtra optional options controlling how this event listener is added.

Returns: void

void

For example in the case of QPushButton:

const button = new QPushButton();
button.addEventListener('clicked',(checked)=>console.log("clicked"));
// here clicked is a value from QPushButtonSignals interface

â–¸ addEventListener(eventType: WidgetEventTypes, callback: function, options?: EventListenerOptions): void

Inherited from EventWidget.addEventListener

Parameters:

â–ª eventType: WidgetEventTypes

â–ª callback: function

▸ (event?: NativeRawPointer‹"QEvent"›): void

Parameters:

NameType
event?NativeRawPointer‹"QEvent"›

â–ªOptional options: EventListenerOptions

Extra optional options controlling how this event listener is added.

For example in the case of QPushButton:

const button = new QPushButton();
button.addEventListener(WidgetEventTypes.HoverEnter,()=>console.log("hovered"));

Returns: void


adjustSize

â–¸ adjustSize(): void

Returns: void


autoFillBackground

â–¸ autoFillBackground(): boolean

Returns: boolean


baseSize

â–¸ baseSize(): QSize

Returns: QSize


childAt

â–¸ childAt(x: number, y: number): QWidget

Parameters:

NameType
xnumber
ynumber

Returns: QWidget


children

â–¸ children(): QObject[]

Inherited from QObject.children

Returns: QObject[]


childrenRect

â–¸ childrenRect(): QRect

Returns: QRect


clearFocus

â–¸ clearFocus(): void

Returns: void


clearMask

â–¸ clearMask(): void

Returns: void


close

â–¸ close(): boolean

Returns: boolean


colorCount

â–¸ colorCount(): number

Returns: number


contentsRect

â–¸ contentsRect(): QRect

Returns: QRect


contextMenuPolicy

â–¸ contextMenuPolicy(): ContextMenuPolicy

Returns: ContextMenuPolicy


delete

â–¸ delete(): void

Inherited from QObject.delete

Returns: void


deleteLater

â–¸ deleteLater(): void

Inherited from QObject.deleteLater

Returns: void


depth

â–¸ depth(): number

Returns: number


devicePixelRatio

â–¸ devicePixelRatio(): number

Returns: number


devicePixelRatioF

â–¸ devicePixelRatioF(): number

Returns: number


dumpObjectInfo

â–¸ dumpObjectInfo(): void

Inherited from QObject.dumpObjectInfo

Returns: void


dumpObjectTree

â–¸ dumpObjectTree(): void

Inherited from QObject.dumpObjectTree

Returns: void


ensurePolished

â–¸ ensurePolished(): void

Returns: void


eventProcessed

â–¸ eventProcessed(): boolean

Inherited from EventWidget.eventProcessed

Get the state of the event processed flag

See setEventProcessed().

Returns: boolean

boolean True if the current event is flagged as processed.


focusProxy

â–¸ focusProxy(): QWidget

Returns: QWidget


focusWidget

â–¸ focusWidget(): QWidget

Returns: QWidget


font

â–¸ font(): QFont

Returns: QFont


frameGeometry

â–¸ frameGeometry(): QRect

Returns: QRect


frameSize

â–¸ frameSize(): QSize

Returns: QSize


geometry

â–¸ geometry(): QRect

Returns: QRect


getFlexNode

â–¸ getFlexNode(): FlexNode

Inherited from YogaWidget.getFlexNode

Returns: FlexNode


grab

â–¸ grab(rect?: QRect): QPixmap

Parameters:

NameType
rect?QRect

Returns: QPixmap


grabKeyboard

â–¸ grabKeyboard(): void

Returns: void


grabMouse

â–¸ grabMouse(): void

Returns: void


hasFocus

â–¸ hasFocus(): boolean

Returns: boolean


hasHeightForWidth

â–¸ hasHeightForWidth(): boolean

Returns: boolean


hasMouseTracking

â–¸ hasMouseTracking(): boolean

Returns: boolean


hasTabletTracking

â–¸ hasTabletTracking(): boolean

Returns: boolean


height

â–¸ height(): number

Returns: number


heightForWidth

â–¸ heightForWidth(w: number): number

Parameters:

NameType
wnumber

Returns: number


heightMM

â–¸ heightMM(): number

Returns: number


hide

â–¸ hide(): void

Returns: void


inherits

â–¸ inherits(className: string): boolean

Inherited from QObject.inherits

Parameters:

NameType
classNamestring

Returns: boolean


inputMethodHints

â–¸ inputMethodHints(): number

Returns: number


isActiveWindow

â–¸ isActiveWindow(): boolean

Returns: boolean


isAncestorOf

â–¸ isAncestorOf(child: QWidget): boolean

Parameters:

NameType
childQWidget

Returns: boolean


isEnabled

â–¸ isEnabled(): boolean

Returns: boolean


isEnabledTo

â–¸ isEnabledTo(ancestor: QWidget): boolean

Parameters:

NameType
ancestorQWidget

Returns: boolean


isFullScreen

â–¸ isFullScreen(): boolean

Returns: boolean


isHidden

â–¸ isHidden(): boolean

Returns: boolean


isMaximized

â–¸ isMaximized(): boolean

Returns: boolean


isMinimized

â–¸ isMinimized(): boolean

Returns: boolean


isModal

â–¸ isModal(): boolean

Returns: boolean


isVisible

â–¸ isVisible(): boolean

Returns: boolean


isVisibleTo

â–¸ isVisibleTo(ancestor: QWidget): boolean

Parameters:

NameType
ancestorQWidget

Returns: boolean


isWindow

â–¸ isWindow(): boolean

Returns: boolean


isWindowModified

â–¸ isWindowModified(): boolean

Returns: boolean


killTimer

â–¸ killTimer(timerId: number): void

Inherited from QObject.killTimer

Parameters:

NameType
timerIdnumber

Returns: void


layout

â–¸ layout(): QLayout | null

Returns: QLayout | null


logicalDpiX

â–¸ logicalDpiX(): number

Returns: number


logicalDpiY

â–¸ logicalDpiY(): number

Returns: number


lower

â–¸ lower(): void

Returns: void


mapFrom

â–¸ mapFrom(parent: QWidget, pos: QPoint): QPoint

Parameters:

NameType
parentQWidget
posQPoint

Returns: QPoint


mapFromGlobal

â–¸ mapFromGlobal(pos: QPoint): QPoint

Parameters:

NameType
posQPoint

Returns: QPoint


mapFromParent

â–¸ mapFromParent(pos: QPoint): QPoint

Parameters:

NameType
posQPoint

Returns: QPoint


mapTo

â–¸ mapTo(parent: QWidget, pos: QPoint): QPoint

Parameters:

NameType
parentQWidget
posQPoint

Returns: QPoint


mapToGlobal

â–¸ mapToGlobal(pos: QPoint): QPoint

Parameters:

NameType
posQPoint

Returns: QPoint


mapToParent

â–¸ mapToParent(pos: QPoint): QPoint

Parameters:

NameType
posQPoint

Returns: QPoint


maximumHeight

â–¸ maximumHeight(): number

Returns: number


maximumSize

â–¸ maximumSize(): QSize

Returns: QSize


maximumWidth

â–¸ maximumWidth(): number

Returns: number


minimumHeight

â–¸ minimumHeight(): number

Returns: number


minimumSize

â–¸ minimumSize(): QSize

Returns: QSize


minimumSizeHint

â–¸ minimumSizeHint(): QSize

Returns: QSize


minimumWidth

â–¸ minimumWidth(): number

Returns: number


move

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

Parameters:

NameType
xnumber
ynumber

Returns: void


nativeParentWidget

â–¸ nativeParentWidget(): QWidget

Returns: QWidget


nextInFocusChain

â–¸ nextInFocusChain(): QWidget

Returns: QWidget


normalGeometry

â–¸ normalGeometry(): QRect

Returns: QRect


objectName

â–¸ objectName(): string

Inherited from QObject.objectName

Returns: string


paintingActive

â–¸ paintingActive(): boolean

Returns: boolean


parent

â–¸ parent(): QObject

Inherited from QObject.parent

Returns: QObject


parentWidget

â–¸ parentWidget(): QWidget

Returns: QWidget


physicalDpiX

â–¸ physicalDpiX(): number

Returns: number


physicalDpiY

â–¸ physicalDpiY(): number

Returns: number


pos

â–¸ pos(): object

Returns: object

  • x: number

  • y: number


previousInFocusChain

â–¸ previousInFocusChain(): QWidget

Returns: QWidget


property

â–¸ property(name: string): QVariant

Inherited from QObject.property

Parameters:

NameType
namestring

Returns: QVariant


raise

â–¸ raise(): void

Returns: void


rect

â–¸ rect(): QRect

Returns: QRect


releaseKeyboard

â–¸ releaseKeyboard(): void

Returns: void


releaseMouse

â–¸ releaseMouse(): void

Returns: void


releaseShortcut

â–¸ releaseShortcut(id: number): void

Parameters:

NameType
idnumber

Returns: void


removeAction

â–¸ removeAction(action: QAction): void

Parameters:

NameType
actionQAction

Returns: void


removeEventListener

▸ removeEventListener‹SignalType›(signalType: SignalType, callback: Signals[SignalType], options?: EventListenerOptions): void

Inherited from EventWidget.removeEventListener

Type parameters:

â–ª SignalType: keyof Signals

Parameters:

NameType
signalTypeSignalType
callbackSignals[SignalType]
options?EventListenerOptions

Returns: void

â–¸ removeEventListener(eventType: WidgetEventTypes, callback: function, options?: EventListenerOptions): void

Inherited from EventWidget.removeEventListener

Parameters:

â–ª eventType: WidgetEventTypes

â–ª callback: function

▸ (event?: NativeRawPointer‹"QEvent"›): void

Parameters:

NameType
event?NativeRawPointer‹"QEvent"›

â–ªOptional options: EventListenerOptions

Returns: void


repaint

â–¸ repaint(): void

Returns: void


repolish

â–¸ repolish(): void

Returns: void


resize

â–¸ resize(width: number, height: number): void

Parameters:

NameType
widthnumber
heightnumber

Returns: void


setAcceptDrops

â–¸ setAcceptDrops(on: boolean): void

Parameters:

NameType
onboolean

Returns: void


setAccessibleDescription

â–¸ setAccessibleDescription(description: string): void

Parameters:

NameType
descriptionstring

Returns: void


setAccessibleName

â–¸ setAccessibleName(name: string): void

Parameters:

NameType
namestring

Returns: void


setAttribute

â–¸ setAttribute(attribute: WidgetAttribute, switchOn: boolean): void

Parameters:

NameType
attributeWidgetAttribute
switchOnboolean

Returns: void


setAutoFillBackground

â–¸ setAutoFillBackground(enabled: boolean): void

Parameters:

NameType
enabledboolean

Returns: void


setBaseSize

â–¸ setBaseSize(size: QSize): void

Parameters:

NameType
sizeQSize

Returns: void


setContentsMargins

â–¸ setContentsMargins(left: number, top: number, right: number, bottom: number): void

Parameters:

NameType
leftnumber
topnumber
rightnumber
bottomnumber

Returns: void


setContextMenuPolicy

â–¸ setContextMenuPolicy(contextMenuPolicy: ContextMenuPolicy): void

Parameters:

NameType
contextMenuPolicyContextMenuPolicy

Returns: void


setCursor

â–¸ setCursor(cursor: CursorShape | QCursor): void

Parameters:

NameType
cursorCursorShape | QCursor

Returns: void


setDisabled

â–¸ setDisabled(disable: boolean): void

Parameters:

NameType
disableboolean

Returns: void


setEnabled

â–¸ setEnabled(enabled: boolean): void

Parameters:

NameType
enabledboolean

Returns: void


setEventProcessed

â–¸ setEventProcessed(isProcessed: boolean): void

Inherited from EventWidget.setEventProcessed

Mark the current event as having been processed

This method is used to indicate that the currently dispatched event has been processed and no further processing by superclasses is required. It only makes sense to call this method from an event handler.

When set, this flag will cause NodeGui's QObject::event() method to return true and not call the superclass event(), effectively preventing any further processing on this event.

Parameters:

NameTypeDescription
isProcessedbooleantrue if the event has been processed.

Returns: void


setFixedHeight

â–¸ setFixedHeight(h: number): void

Parameters:

NameType
hnumber

Returns: void


setFixedSize

â–¸ setFixedSize(width: number, height: number): void

Parameters:

NameType
widthnumber
heightnumber

Returns: void


setFixedWidth

â–¸ setFixedWidth(w: number): void

Parameters:

NameType
wnumber

Returns: void


setFlexNodeSizeControlled

â–¸ setFlexNodeSizeControlled(isSizeControlled: boolean): void

Inherited from YogaWidget.setFlexNodeSizeControlled

sets whether the widget's size is controlled by someone else (for example a window's size is controlled by its frame when dragged).

Parameters:

NameTypeDescription
isSizeControlledboolean

Returns: void


setFocus

â–¸ setFocus(reason: FocusReason): void

Parameters:

NameTypeDefault
reasonFocusReasonFocusReason.OtherFocusReason

Returns: void


setFocusPolicy

â–¸ setFocusPolicy(policy: FocusPolicy): void

Parameters:

NameType
policyFocusPolicy

Returns: void


setFocusProxy

â–¸ setFocusProxy(widget: QWidget): void

Parameters:

NameType
widgetQWidget

Returns: void


setFont

â–¸ setFont(font: QFont): void

Parameters:

NameType
fontQFont

Returns: void


setGeometry

â–¸ setGeometry(x: number, y: number, w: number, h: number): void

Parameters:

NameType
xnumber
ynumber
wnumber
hnumber

Returns: void


setGraphicsEffect

▸ setGraphicsEffect(effect: QGraphicsEffect‹any›): void

Parameters:

NameType
effectQGraphicsEffect‹any›

Returns: void


setHidden

â–¸ setHidden(hidden: boolean): void

Parameters:

NameType
hiddenboolean

Returns: void


setInlineStyle

â–¸ setInlineStyle(style: string, postprocess: boolean): void

Parameters:

NameTypeDefault
stylestring-
postprocessbooleantrue

Returns: void


setInputMethodHints

â–¸ setInputMethodHints(hints: number): void

Parameters:

NameType
hintsnumber

Returns: void


setLayout

â–¸ setLayout(layout: QLayout): void

Parameters:

NameType
layoutQLayout

Returns: void


setMaximumHeight

â–¸ setMaximumHeight(maxh: number): void

Parameters:

NameType
maxhnumber

Returns: void


setMaximumSize

â–¸ setMaximumSize(maxw: number, maxh: number): void

Parameters:

NameType
maxwnumber
maxhnumber

Returns: void


setMaximumWidth

â–¸ setMaximumWidth(maxw: number): void

Parameters:

NameType
maxwnumber

Returns: void


setMinimumHeight

â–¸ setMinimumHeight(minh: number): void

Parameters:

NameType
minhnumber

Returns: void


setMinimumSize

â–¸ setMinimumSize(minw: number, minh: number): void

Parameters:

NameType
minwnumber
minhnumber

Returns: void


setMinimumWidth

â–¸ setMinimumWidth(minw: number): void

Parameters:

NameType
minwnumber

Returns: void


setMouseTracking

â–¸ setMouseTracking(isMouseTracked: boolean): void

Parameters:

NameType
isMouseTrackedboolean

Returns: void


setObjectName

â–¸ setObjectName(objectName: string): void

Overrides QObject.setObjectName

Parameters:

NameType
objectNamestring

Returns: void


setParent

â–¸ setParent(parent: QObject): void

Inherited from QObject.setParent

Parameters:

NameType
parentQObject

Returns: void


setProperty

â–¸ setProperty(name: string, value: QVariantType): boolean

Inherited from QObject.setProperty

Parameters:

NameType
namestring
valueQVariantType

Returns: boolean


setShortcutAutoRepeat

â–¸ setShortcutAutoRepeat(id: number, enable: boolean): void

Parameters:

NameTypeDefault
idnumber-
enablebooleantrue

Returns: void


setShortcutEnabled

â–¸ setShortcutEnabled(id: number, enable: boolean): void

Parameters:

NameTypeDefault
idnumber-
enablebooleantrue

Returns: void


setSizeIncrement

â–¸ setSizeIncrement(w_or_size: QSize | number, h: number): void

Parameters:

NameTypeDefault
w_or_sizeQSize | number-
hnumber0

Returns: void


setSizePolicy

â–¸ setSizePolicy(horizontal: QSizePolicyPolicy, vertical: QSizePolicyPolicy): void

Parameters:

NameType
horizontalQSizePolicyPolicy
verticalQSizePolicyPolicy

Returns: void


setStatusTip

â–¸ setStatusTip(statusTip: string): void

Parameters:

NameType
statusTipstring

Returns: void


setStyleSheet

â–¸ setStyleSheet(styleSheet: string, postprocess: boolean): void

Parameters:

NameTypeDefault
styleSheetstring-
postprocessbooleantrue

Returns: void


setTabletTracking

â–¸ setTabletTracking(enable: boolean): void

Parameters:

NameType
enableboolean

Returns: void


setToolTip

â–¸ setToolTip(text: string): void

Parameters:

NameType
textstring

Returns: void


setToolTipDuration

â–¸ setToolTipDuration(msec: number): void

Parameters:

NameType
msecnumber

Returns: void


setUpdatesEnabled

â–¸ setUpdatesEnabled(enable: boolean): void

Parameters:

NameType
enableboolean

Returns: void


setVisible

â–¸ setVisible(visible: boolean): void

Parameters:

NameType
visibleboolean

Returns: void


setWhatsThis

â–¸ setWhatsThis(whatsThis: string): void

Parameters:

NameType
whatsThisstring

Returns: void


setWindowFilePath

â–¸ setWindowFilePath(filePath: string): void

Parameters:

NameType
filePathstring

Returns: void


setWindowFlag

â–¸ setWindowFlag(windowType: WindowType, switchOn: boolean): void

Parameters:

NameType
windowTypeWindowType
switchOnboolean

Returns: void


setWindowIcon

â–¸ setWindowIcon(icon: QIcon): void

Parameters:

NameType
iconQIcon

Returns: void


setWindowModified

â–¸ setWindowModified(modified: boolean): void

Parameters:

NameType
modifiedboolean

Returns: void


setWindowOpacity

â–¸ setWindowOpacity(opacity: number): void

Parameters:

NameType
opacitynumber

Returns: void


setWindowRole

â–¸ setWindowRole(role: string): void

Parameters:

NameType
rolestring

Returns: void


setWindowState

â–¸ setWindowState(state: WindowState): void

Parameters:

NameType
stateWindowState

Returns: void


setWindowTitle

â–¸ setWindowTitle(title: string): void

Parameters:

NameType
titlestring

Returns: void


show

â–¸ show(): void

Returns: void


showFullScreen

â–¸ showFullScreen(): void

Returns: void


showMaximized

â–¸ showMaximized(): void

Returns: void


showMinimized

â–¸ showMinimized(): void

Returns: void


showNormal

â–¸ showNormal(): void

Returns: void


size

â–¸ size(): QSize

Returns: QSize


sizeHint

â–¸ sizeHint(): QSize

Returns: QSize


sizeIncrement

â–¸ sizeIncrement(): QSize

Returns: QSize


stackUnder

â–¸ stackUnder(w: QWidget): void

Parameters:

NameType
wQWidget

Returns: void


startTimer

â–¸ startTimer(intervalMS: number, timerType: TimerType): number

Inherited from QObject.startTimer

Parameters:

NameTypeDefault
intervalMSnumber-
timerTypeTimerTypeTimerType.CoarseTimer

Returns: number


statusTip

â–¸ statusTip(): string

Returns: string


style

â–¸ style(): QStyle

Returns: QStyle


styleSheet

â–¸ styleSheet(): string

Returns: string


testAttribute

â–¸ testAttribute(attribute: WidgetAttribute): boolean

Parameters:

NameType
attributeWidgetAttribute

Returns: boolean


toolTip

â–¸ toolTip(): string

Returns: string


toolTipDuration

â–¸ toolTipDuration(): number

Returns: number


underMouse

â–¸ underMouse(): boolean

Returns: boolean


unsetCursor

â–¸ unsetCursor(): void

Returns: void


unsetLayoutDirection

â–¸ unsetLayoutDirection(): void

Returns: void


unsetLocale

â–¸ unsetLocale(): void

Returns: void


update

â–¸ update(): void

Returns: void


updateGeometry

â–¸ updateGeometry(): void

Returns: void


updateMicroFocus

â–¸ updateMicroFocus(query: number): void

Parameters:

NameTypeDefault
querynumberInputMethodQuery.ImQueryAll

Returns: void


updatesEnabled

â–¸ updatesEnabled(): boolean

Returns: boolean


whatsThis

â–¸ whatsThis(): string

Returns: string


width

â–¸ width(): number

Returns: number


widthMM

â–¸ widthMM(): number

Returns: number


winId

â–¸ winId(): number

Returns: number


window

â–¸ window(): QWidget

Returns: QWidget


windowFilePath

â–¸ windowFilePath(): string

Returns: string


windowHandle

â–¸ windowHandle(): QWindow | null

Returns: QWindow | null


windowIcon

â–¸ windowIcon(): QIcon

Returns: QIcon


windowOpacity

â–¸ windowOpacity(): number

Returns: number


windowRole

â–¸ windowRole(): string

Returns: string


windowState

â–¸ windowState(): WindowState

Returns: WindowState


windowTitle

â–¸ windowTitle(): string

Returns: string


x

â–¸ x(): number

Returns: number


y

â–¸ y(): number

Returns: number