Merge pull request #67 from nodegui/feature/checkbox

adds checkbox check prop
This commit is contained in:
Atul R 2019-08-26 17:24:39 +02:00 committed by GitHub
commit 56b81f8027
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 1 deletions

View File

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

View File

@ -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<Napi::Boolean>();
this->instance->setChecked(check.Value());
return env.Null();
}

View File

@ -17,7 +17,9 @@ class QCheckBoxWrap : public Napi::ObjectWrap<QCheckBoxWrap>{
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
};

View File

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

View File

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