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: unknown

Hierarchy

Index

Constructors

Properties

Methods

Constructors

constructor

+ new EventWidget(native: NativeElement): EventWidget

Overrides Component.constructor

Parameters:

NameType
nativeNativeElement

Returns: EventWidget

Properties

native

• native: NativeElement | null

Inherited from Component.native

Methods

addEventListener

▸ addEventListener‹SignalType›(signalType: SignalType, callback: Signals[SignalType], options?: EventListenerOptions): 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
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

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


eventProcessed

â–¸ eventProcessed(): boolean

Get the state of the event processed flag

See setEventProcessed().

Returns: boolean

boolean True if the current event is flagged as processed.


removeEventListener

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

Type parameters:

â–ª SignalType: keyof Signals

Parameters:

NameType
signalTypeSignalType
callbackSignals[SignalType]
options?EventListenerOptions

Returns: void

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

Parameters:

â–ª eventType: WidgetEventTypes

â–ª callback: function

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

Parameters:

NameType
event?NativeRawPointer‹"QEvent"›

â–ªOptional options: EventListenerOptions

Returns: void


setEventProcessed

â–¸ setEventProcessed(isProcessed: boolean): void

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