adds checkbox check prop
This commit is contained in:
parent
0921668ae8
commit
05c67d7882
@ -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
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
};
|
||||
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user