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:
Name | Type |
---|---|
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
Parameters:
Name | Type |
---|---|
widget | QWidget |
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
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:
Name | Type |
---|---|
widget | QWidget |
Returns: number
inherits
▸ inherits(className
: string): boolean
Inherited from QObject.inherits
Parameters:
Name | Type |
---|---|
className | string |
Returns: boolean
insertWidget
▸ insertWidget(index
: number, widget
: QWidget): void
Parameters:
Name | Type |
---|---|
index | number |
widget | QWidget |
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:
Name | Type |
---|---|
timerId | number |
Returns: void
objectName
▸ objectName(): string
Inherited from QObject.objectName
Returns: string
parent
▸ parent(): QObject
Returns: QObject
property
▸ property(name
: string): QVariant
Inherited from QObject.property
Parameters:
Name | Type |
---|---|
name | string |
Returns: QVariant
removeEventListener
▸ removeEventListener‹SignalType›(signalType
: SignalType, callback
: QStackedLayoutSignals[SignalType], options?
: EventListenerOptions): void
Inherited from EventWidget.removeEventListener
Type parameters:
▪ SignalType: keyof QStackedLayoutSignals
Parameters:
Name | Type |
---|---|
signalType | SignalType |
callback | QStackedLayoutSignals[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:
Name | Type |
---|---|
event? | NativeRawPointer‹"QEvent"› |
▪Optional
options: EventListenerOptions
Returns: void
removeWidget
▸ removeWidget(widget
: QWidget): void
Overrides QLayout.removeWidget
Parameters:
Name | Type |
---|---|
widget | QWidget |
Returns: void
setContentsMargins
▸ setContentsMargins(left
: number, top
: number, right
: number, bottom
: number): void
Inherited from QLayout.setContentsMargins
Parameters:
Name | Type |
---|---|
left | number |
top | number |
right | number |
bottom | number |
Returns: void
setCurrentIndex
▸ setCurrentIndex(index
: number): void
Parameters:
Name | Type |
---|---|
index | number |
Returns: void
setCurrentWidget
▸ setCurrentWidget(widget
: QWidget): void
Parameters:
Name | Type |
---|---|
widget | QWidget |
Returns: void
setEnabled
▸ setEnabled(enable
: boolean): void
Inherited from QLayout.setEnabled
Parameters:
Name | Type |
---|---|
enable | boolean |
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:
Name | Type | Description |
---|---|---|
isProcessed | boolean | true if the event has been processed. |
Returns: void
setObjectName
▸ setObjectName(objectName
: string): void
Inherited from QObject.setObjectName
Parameters:
Name | Type |
---|---|
objectName | string |
Returns: void
setParent
▸ setParent(parent
: QObject): void
Inherited from QObject.setParent
Parameters:
Name | Type |
---|---|
parent | QObject |
Returns: void
setProperty
▸ setProperty(name
: string, value
: QVariantType): boolean
Inherited from QObject.setProperty
Parameters:
Name | Type |
---|---|
name | string |
value | QVariantType |
Returns: boolean
setSizeConstraint
▸ setSizeConstraint(constraint
: SizeConstraint): void
Inherited from QLayout.setSizeConstraint
Parameters:
Name | Type |
---|---|
constraint | SizeConstraint |
Returns: void
setSpacing
▸ setSpacing(spacing
: number): void
Inherited from QLayout.setSpacing
Parameters:
Name | Type |
---|---|
spacing | number |
Returns: void
setStackingMode
▸ setStackingMode(stackingMode
: StackingMode): void
Parameters:
Name | Type |
---|---|
stackingMode | StackingMode |
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:
Name | Type | Default |
---|---|---|
intervalMS | number | - |
timerType | TimerType | TimerType.CoarseTimer |
Returns: number
update
▸ update(): void
Returns: void
widget
▸ widget(index
: number): QWidget
Parameters:
Name | Type |
---|---|
index | number |
Returns: QWidget