EventWidget

Abstract class that adds event handling support to all widgets.

*This class implements an event emitter and merges it with Qt's event and signal system. It allows us to register and unregister event and signal listener at will from javascript**

EventWidget is an abstract class and hence no instances of the same should be created. It exists so that we can add event handling functionalities to all widget's easily. This is an internal class.

Example

const { QWidget, QWidgetSignals, WidgetEventTypes } = require("@nodegui/nodegui");
const view = new QWidget();
// You either listen for a widget's signal
view.addEventListener('windowTitleChanged', () => {
console.log("window title changed");
});
// or you can listen for an event
view.addEventListener(WidgetEventTypes.MouseMove, () => {
console.log("mouse moved");
});

Type parameters

Signals: __type

Hierarchy

Index

Constructors

Properties

Methods

Constructors

constructor

+ new EventWidget(native: NativeElement): EventWidget

Overrides Component.constructor

Parameters:

NameType
nativeNativeElement

Returns: EventWidget

Properties

Abstract native

native: NativeElement

Inherited from Component.native


nodeChildren

nodeChildren: Set‹Component

Inherited from Component.nodeChildren


Optional nodeParent

nodeParent? : Component

Inherited from Component.nodeParent

Methods

addEventListener

addEventListener<SignalType>(signalType: SignalType, callback: Signals[SignalType]): void

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

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): void

Parameters:

eventType: WidgetEventTypes

callback: function

For example in the case of QPushButton:

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

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

Parameters:

NameType
event?NativeRawPointer‹"QEvent"›

Returns: void


removeEventListener

removeEventListener<SignalType>(signalType: SignalType, callback: Signals[SignalType]): void

Type parameters:

SignalType: keyof Signals

Parameters:

NameType
signalTypeSignalType
callbackSignals[SignalType]

Returns: void

removeEventListener(eventType: WidgetEventTypes, callback: function): void

Parameters:

eventType: WidgetEventTypes

callback: function

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

Parameters:

NameType
event?NativeRawPointer‹"QEvent"›

Returns: void


setNodeParent

setNodeParent(parent?: Component): void

Inherited from Component.setNodeParent

Parameters:

NameType
parent?Component

Returns: void