QStackedLayout

The QStackedLayout class provides a stack of widgets where only one widget is visible at a time

This class is a JS wrapper around Qt's QStackedLayout

Example

const { QStackedLayout, QWidget, QLabel, QBoxLayout, QCombobox } = require("@nodegui/nodegui");
const centralWidget = new QWidget();
centralWidget.setObjectName('myroot');
const rootLayout = new QBoxLayout(Direction.TopToBottom);
centralWidget.setLayout(rootLayout);
const stackedLayout = new QStackedLayout()
const page1 = new QWidget();
const page1_layout = new FlexLayout();
page1.setLayout(page1_layout)
const label1 = new QLabel();
label1.setText("This is page 1")
page1_layout.addWidget(label1);
const page2 = new QWidget();
const page2_layout = new FlexLayout();
page2.setLayout(page2_layout)
const label2 = new QLabel();
label2.setText("This is page 2")
page2_layout.addWidget(label2);
const page3 = new QWidget();
const page3_layout = new FlexLayout();
page3.setLayout(page3_layout)
const label3 = new QLabel();
label3.setText("This is page 3")
page3_layout.addWidget(label3);
stackedLayout.addWidget(page1)
stackedLayout.addWidget(page2)
stackedLayout.addWidget(page3)
const combobox = new QComboBox()
combobox.addItems(["Page 1", "Page 2", "Page 3"])
combobox.addEventListener("currentIndexChanged", (index) => stackedLayout.setCurrentIndex(index));
rootLayout.addWidget(combobox);
const currentIndexLabel = new QLabel()
currentIndexLabel.setText(`Current Index: ${stackedLayout.currentIndex()}`)
stackedLayout.addEventListener("currentChanged", (index) => {
currentIndexLabel.setText(`Current Index: ${index}`)
});
rootLayout.addWidget(currentIndexLabel);
rootLayout.addLayout(stackedLayout);
## Hierarchy
↳ [QLayout](qlayout.md)‹[QStackedLayoutSignals](../interfaces/qstackedlayoutsignals.md)›
↳ **QStackedLayout**
## Index
### Constructors
* [constructor](qstackedlayout.md#constructor)
### Properties
* [native](qstackedlayout.md#native)
* [type](qstackedlayout.md#type)
### Methods
* [_id](qstackedlayout.md#_id)
* [activate](qstackedlayout.md#activate)
* [addEventListener](qstackedlayout.md#addeventlistener)
* [addWidget](qstackedlayout.md#addwidget)
* [children](qstackedlayout.md#children)
* [count](qstackedlayout.md#count)
* [currentIndex](qstackedlayout.md#currentindex)
* [currentWidget](qstackedlayout.md#currentwidget)
* [delete](qstackedlayout.md#delete)
* [deleteLater](qstackedlayout.md#deletelater)
* [dumpObjectInfo](qstackedlayout.md#dumpobjectinfo)
* [dumpObjectTree](qstackedlayout.md#dumpobjecttree)
* [eventProcessed](qstackedlayout.md#eventprocessed)
* [indexOf](qstackedlayout.md#indexof)
* [inherits](qstackedlayout.md#inherits)
* [insertWidget](qstackedlayout.md#insertwidget)
* [invalidate](qstackedlayout.md#invalidate)
* [isEnabled](qstackedlayout.md#isenabled)
* [killTimer](qstackedlayout.md#killtimer)
* [objectName](qstackedlayout.md#objectname)
* [parent](qstackedlayout.md#parent)
* [property](qstackedlayout.md#property)
* [removeEventListener](qstackedlayout.md#removeeventlistener)
* [removeWidget](qstackedlayout.md#removewidget)
* [setContentsMargins](qstackedlayout.md#setcontentsmargins)
* [setCurrentIndex](qstackedlayout.md#setcurrentindex)
* [setCurrentWidget](qstackedlayout.md#setcurrentwidget)
* [setEnabled](qstackedlayout.md#setenabled)
* [setEventProcessed](qstackedlayout.md#seteventprocessed)
* [setObjectName](qstackedlayout.md#setobjectname)
* [setParent](qstackedlayout.md#setparent)
* [setProperty](qstackedlayout.md#setproperty)
* [setSizeConstraint](qstackedlayout.md#setsizeconstraint)
* [setSpacing](qstackedlayout.md#setspacing)
* [setStackingMode](qstackedlayout.md#setstackingmode)
* [sizeConstraint](qstackedlayout.md#sizeconstraint)
* [spacing](qstackedlayout.md#spacing)
* [stackingMode](qstackedlayout.md#stackingmode)
* [startTimer](qstackedlayout.md#starttimer)
* [update](qstackedlayout.md#update)
* [widget](qstackedlayout.md#widget)
## Constructors
### constructor
\+ **new QStackedLayout**(`arg?`: [QWidget](qwidget.md)‹[QWidgetSignals](../interfaces/qwidgetsignals.md)› | [NativeElement](../globals.md#nativeelement)): *[QStackedLayout](qstackedlayout.md)*
*Overrides [QObject](qobject.md).[constructor](qobject.md#constructor)*
**Parameters:**
Name | Type |
------ | ------ |
`arg?` | [QWidget](qwidget.md)‹[QWidgetSignals](../interfaces/qwidgetsignals.md)› | [NativeElement](../globals.md#nativeelement) |
**Returns:** *[QStackedLayout](qstackedlayout.md)*
## Properties
### native
• **native**: *[NativeElement](../globals.md#nativeelement) | null*
*Inherited from [Component](component.md).[native](component.md#native)*
___
### type
• **type**: *string* = "layout"
*Inherited from [QLayout](qlayout.md).[type](qlayout.md#type)*
## Methods
### _id
â–¸ **_id**(): *number*
*Inherited from [QObject](qobject.md).[_id](qobject.md#_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.
___
### activate
â–¸ **activate**(): *boolean*
*Inherited from [QLayout](qlayout.md).[activate](qlayout.md#activate)*
**Returns:** *boolean*
___
### addEventListener
▸ **addEventListener**‹**SignalType**›(`signalType`: SignalType, `callback`: QStackedLayoutSignals[SignalType], `options?`: [EventListenerOptions](../interfaces/eventlisteneroptions.md)): *void*
*Inherited from [EventWidget](eventwidget.md).[addEventListener](eventwidget.md#addeventlistener)*
**Type parameters:**
â–ª **SignalType**: *keyof QStackedLayoutSignals*
**Parameters:**
Name | Type | Description |
------ | ------ | ------ |
`signalType` | SignalType | SignalType is a signal from the widgets signals interface. |
`callback` | QStackedLayoutSignals[SignalType] | Corresponding callback for the signal as mentioned in the widget's signal interface |
`options?` | [EventListenerOptions](../interfaces/eventlisteneroptions.md) | Extra optional options controlling how this event listener is added. |
**Returns:** *void*
void
For example in the case of QPushButton:
```js
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


addWidget

â–¸ addWidget(widget: QWidget): void

Overrides QLayout.addWidget

Parameters:

NameType
widgetQWidget

Returns: void


children

â–¸ children(): QObject[]

Inherited from QObject.children

Returns: QObject[]


count

â–¸ count(): number

Returns: number


currentIndex

â–¸ currentIndex(): number

Returns: number


currentWidget

â–¸ currentWidget(): QWidget

Returns: QWidget


delete

â–¸ delete(): void

Inherited from QObject.delete

Returns: void


deleteLater

â–¸ deleteLater(): void

Inherited from QObject.deleteLater

Returns: void


dumpObjectInfo

â–¸ dumpObjectInfo(): void

Inherited from QObject.dumpObjectInfo

Returns: void


dumpObjectTree

â–¸ dumpObjectTree(): void

Inherited from QObject.dumpObjectTree

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.


indexOf

â–¸ indexOf(widget: QWidget): number

Parameters:

NameType
widgetQWidget

Returns: number


inherits

â–¸ inherits(className: string): boolean

Inherited from QObject.inherits

Parameters:

NameType
classNamestring

Returns: boolean


insertWidget

â–¸ insertWidget(index: number, widget: QWidget): void

Parameters:

NameType
indexnumber
widgetQWidget

Returns: void


invalidate

â–¸ invalidate(): void

Inherited from QLayout.invalidate

Returns: void


isEnabled

â–¸ isEnabled(): boolean

Inherited from QLayout.isEnabled

Returns: boolean


killTimer

â–¸ killTimer(timerId: number): void

Inherited from QObject.killTimer

Parameters:

NameType
timerIdnumber

Returns: void


objectName

â–¸ objectName(): string

Inherited from QObject.objectName

Returns: string


parent

â–¸ parent(): QObject

Inherited from QObject.parent

Returns: QObject


property

â–¸ property(name: string): QVariant

Inherited from QObject.property

Parameters:

NameType
namestring

Returns: QVariant


removeEventListener

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

Inherited from EventWidget.removeEventListener

Type parameters:

â–ª SignalType: keyof QStackedLayoutSignals

Parameters:

NameType
signalTypeSignalType
callbackQStackedLayoutSignals[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


removeWidget

â–¸ removeWidget(widget: QWidget): void

Overrides QLayout.removeWidget

Parameters:

NameType
widgetQWidget

Returns: void


setContentsMargins

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

Inherited from QLayout.setContentsMargins

Parameters:

NameType
leftnumber
topnumber
rightnumber
bottomnumber

Returns: void


setCurrentIndex

â–¸ setCurrentIndex(index: number): void

Parameters:

NameType
indexnumber

Returns: void


setCurrentWidget

â–¸ setCurrentWidget(widget: QWidget): void

Parameters:

NameType
widgetQWidget

Returns: void


setEnabled

â–¸ setEnabled(enable: boolean): void

Inherited from QLayout.setEnabled

Parameters:

NameType
enableboolean

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


setObjectName

â–¸ setObjectName(objectName: string): void

Inherited from 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


setSizeConstraint

â–¸ setSizeConstraint(constraint: SizeConstraint): void

Inherited from QLayout.setSizeConstraint

Parameters:

NameType
constraintSizeConstraint

Returns: void


setSpacing

â–¸ setSpacing(spacing: number): void

Inherited from QLayout.setSpacing

Parameters:

NameType
spacingnumber

Returns: void


setStackingMode

â–¸ setStackingMode(stackingMode: StackingMode): void

Parameters:

NameType
stackingModeStackingMode

Returns: void


sizeConstraint

â–¸ sizeConstraint(): SizeConstraint

Inherited from QLayout.sizeConstraint

Returns: SizeConstraint


spacing

â–¸ spacing(): number

Inherited from QLayout.spacing

Returns: number


stackingMode

â–¸ stackingMode(): StackingMode

Returns: StackingMode


startTimer

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

Inherited from QObject.startTimer

Parameters:

NameTypeDefault
intervalMSnumber-
timerTypeTimerTypeTimerType.CoarseTimer

Returns: number


update

â–¸ update(): void

Inherited from QLayout.update

Returns: void


widget

â–¸ widget(index: number): QWidget

Parameters:

NameType
indexnumber

Returns: QWidget