QShortcut

The QShortcut class is used to create keyboard shortcuts.

This class is a JS wrapper around Qt's QShortcut class

Example

const { QShortcut, QKeySequence, QMainWindow } = require("@nodegui/nodegui");
const win = new QMainWindow();
const shortcut = new QShortcut(win);
shortcut.setKey(new QKeySequence("Ctrl+M"));
shortcut.setEnabled(true);
shortcut.addEventListener(QShortcutEvents.activated, () => {
console.log("Shortcut Activated");
});
win.show();
global.win = win;
global.shortcut = shortcut;

Hierarchy

↳ QObject‹QShortcutSignals›

↳ QShortcut

Index

Constructors

Properties

Methods

Constructors

constructor

+ new QShortcut(arg?: QWidget‹QWidgetSignals› | NativeElement): QShortcut

Overrides QObject.constructor

Parameters:

NameType
arg?QWidget‹QWidgetSignals› | NativeElement

Returns: QShortcut

Properties

native

• native: NativeElement | null

Inherited from Component.native

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.


addEventListener

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

Inherited from EventWidget.addEventListener

Type parameters:

â–ª SignalType: keyof QShortcutSignals

Parameters:

NameTypeDescription
signalTypeSignalTypeSignalType is a signal from the widgets signals interface.
callbackQShortcutSignals[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


children

â–¸ children(): QObject[]

Inherited from QObject.children

Returns: QObject[]


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.


inherits

â–¸ inherits(className: string): boolean

Inherited from QObject.inherits

Parameters:

NameType
classNamestring

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: QShortcutSignals[SignalType], options?: EventListenerOptions): void

Inherited from EventWidget.removeEventListener

Type parameters:

â–ª SignalType: keyof QShortcutSignals

Parameters:

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


setAutoRepeat

â–¸ setAutoRepeat(on: boolean): void

Parameters:

NameType
onboolean

Returns: void


setContext

â–¸ setContext(shortcutContext: ShortcutContext): void

Parameters:

NameType
shortcutContextShortcutContext

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


setKey

â–¸ setKey(keysequence: QKeySequence): void

Parameters:

NameType
keysequenceQKeySequence

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


startTimer

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

Inherited from QObject.startTimer

Parameters:

NameTypeDefault
intervalMSnumber-
timerTypeTimerTypeTimerType.CoarseTimer

Returns: number