added support for QCheckBoxEvents.toggled

This commit is contained in:
Roy Sommer 2019-09-12 11:47:40 +03:00
parent e372f750bd
commit 0444c087e4
3 changed files with 15 additions and 1 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

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

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;