diff --git a/docs/api/QCheckBox.md b/docs/api/QCheckBox.md index ddc4e6431..2d5de98f7 100644 --- a/docs/api/QCheckBox.md +++ b/docs/api/QCheckBox.md @@ -40,3 +40,13 @@ Additionally it also has the following instance methods: Sets the given text to the checkbox. - `text` string + +#### `checkbox.isChecked()` + +returns whether the checkbox is checked or not. It calls the native method [QAbstractButton: isChecked](https://doc.qt.io/qt-5/qabstractbutton.html#checked-prop). + +#### `checkbox.setChecked(check)` + +This property holds whether the button is checked. It calls the native method [QAbstractButton: setChecked](https://doc.qt.io/qt-5/qabstractbutton.html#checked-prop). + +- `check` boolean diff --git a/src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.cpp b/src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.cpp index 4b8d89c9d..de0a94b44 100644 --- a/src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.cpp +++ b/src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.cpp @@ -11,6 +11,8 @@ Napi::Object QCheckBoxWrap::init(Napi::Env env, Napi::Object exports) { char CLASSNAME[] = "QCheckBox"; Napi::Function func = DefineClass(env, CLASSNAME, { InstanceMethod("setText", &QCheckBoxWrap::setText), + InstanceMethod("setChecked", &QCheckBoxWrap::setChecked), + InstanceMethod("isChecked", &QCheckBoxWrap::isChecked), QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QCheckBoxWrap) }); constructor = Napi::Persistent(func); @@ -54,3 +56,18 @@ Napi::Value QCheckBoxWrap::setText(const Napi::CallbackInfo& info) { return env.Null(); } +Napi::Value QCheckBoxWrap::isChecked(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + bool isChecked = this->instance->isChecked(); + return Napi::Value::From(env, isChecked); +} + +Napi::Value QCheckBoxWrap::setChecked(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + Napi::Boolean check = info[0].As(); + this->instance->setChecked(check.Value()); + return env.Null(); +} + diff --git a/src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.h b/src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.h index 983a04d10..69bfe2751 100644 --- a/src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.h +++ b/src/cpp/QtWidgets/QCheckBox/qcheckbox_wrap.h @@ -17,7 +17,9 @@ class QCheckBoxWrap : public Napi::ObjectWrap{ static Napi::FunctionReference constructor; //wrapped methods Napi::Value setText(const Napi::CallbackInfo& info); - + Napi::Value isChecked(const Napi::CallbackInfo& info); + Napi::Value setChecked(const Napi::CallbackInfo& info); + QWIDGET_WRAPPED_METHODS_DECLARATION }; diff --git a/src/demo.ts b/src/demo.ts index d050a29e7..02dc8c791 100644 --- a/src/demo.ts +++ b/src/demo.ts @@ -25,6 +25,7 @@ label.setInlineStyle("font-size: 20px;"); const checkbox = new QCheckBox(); checkbox.setText("Check me out?"); checkbox.setObjectName("check"); +checkbox.setChecked(true); const lineEdit = new QLineEdit(); lineEdit.setPlaceholderText("Enter your thoughts here"); diff --git a/src/lib/QtWidgets/QCheckBox/index.ts b/src/lib/QtWidgets/QCheckBox/index.ts index c9d945b50..8bde29167 100644 --- a/src/lib/QtWidgets/QCheckBox/index.ts +++ b/src/lib/QtWidgets/QCheckBox/index.ts @@ -20,9 +20,17 @@ export class QCheckBox extends NodeWidget { this.parent = parent; // bind member functions this.setText.bind(this); + this.isChecked.bind(this); + this.setChecked.bind(this); } setText(text: string) { this.native.setText(text); } + isChecked(): boolean { + return this.native.isChecked(); + } + setChecked(check: boolean) { + return this.native.setChecked(check); + } }