diff --git a/src/cpp/QtWidgets/QCheckBox/ncheckbox.h b/src/cpp/QtWidgets/QCheckBox/ncheckbox.h index e9e660c5b..8ed6054d5 100644 --- a/src/cpp/QtWidgets/QCheckBox/ncheckbox.h +++ b/src/cpp/QtWidgets/QCheckBox/ncheckbox.h @@ -2,12 +2,21 @@ #include #include "src/cpp/core/NodeWidget/nodewidget.h" +#include "napi.h" class NCheckBox: public QCheckBox, public NodeWidget { NODEWIDGET_IMPLEMENTATIONS(QCheckBox) public: using QCheckBox::QCheckBox; //inherit all constructors of QCheckBox + + void connectWidgetSignalsToEventEmitter() { + QObject::connect(this, &QCheckBox::toggled, [=](bool checked) { + Napi::Env env = this->emitOnNode.Env(); + Napi::HandleScope scope(env); + this->emitOnNode.Call({ Napi::String::New(env, "toggled"), Napi::Value::From(env, checked) }); + }); + } }; diff --git a/src/demo.ts b/src/demo.ts index 6d548407a..7fdfec7f6 100644 --- a/src/demo.ts +++ b/src/demo.ts @@ -19,6 +19,7 @@ import { QApplication, QClipboardMode } from "./index"; +import { QCheckBoxEvents } from './lib/QtWidgets/QCheckBox'; const path = require("path"); @@ -33,6 +34,9 @@ const checkbox = new QCheckBox(); checkbox.setText("Check me out?"); checkbox.setObjectName("check"); checkbox.setChecked(true); +checkbox.addEventListener(QCheckBoxEvents.toggled, () => { + console.log('checkbox was toggled!'); +}) const dial = new QDial(); checkbox.setObjectName("dial"); diff --git a/src/lib/QtWidgets/QCheckBox/index.ts b/src/lib/QtWidgets/QCheckBox/index.ts index 7d739c06d..29b6b8127 100644 --- a/src/lib/QtWidgets/QCheckBox/index.ts +++ b/src/lib/QtWidgets/QCheckBox/index.ts @@ -4,7 +4,8 @@ import { BaseWidgetEvents } from "../../core/EventWidget"; import { NativeElement } from "../../core/Component"; export const QCheckBoxEvents = Object.freeze({ - ...BaseWidgetEvents + ...BaseWidgetEvents, + toggled: "toggled" }); export class QCheckBox extends NodeWidget { native: NativeElement;