Merge pull request #93 from illBeRoy/qcheckbox-toggled-event

Added QCheckBoxEvents.toggled
This commit is contained in:
Atul R 2019-09-13 22:55:40 +02:00 committed by GitHub
commit 5e83bb6d75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View File

@ -2,12 +2,21 @@
#include <QCheckBox>
#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) });
});
}
};

View File

@ -17,7 +17,8 @@ import {
WindowState,
QTextOptionWrapMode,
QApplication,
QClipboardMode
QClipboardMode,
QCheckBoxEvents
} from "./index";
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");

View File

@ -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;