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?: QWidgetQWidgetSignals› | NativeElement): QWidget

Overrides QObject.constructor

Parameters:

NameType
arg?QWidgetQWidgetSignals› | 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

addEventListenerSignalType›(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

removeEventListenerSignalType›(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