Add QLineEdit.setReadOnly method

This commit is contained in:
rgabs 2019-08-17 00:43:01 +05:30
parent b84f779ef8
commit 151d9842c1
4 changed files with 22 additions and 1 deletions

View File

@ -51,3 +51,9 @@ Sets the given text to the lineEdit's placeholder.
#### `lineEdit.text()`
Returns the currently set text from native lineEdit widget.
#### `lineEdit.setReadOnly(isReadOnly)`
Sets the lineEdit to be read only. lineEdit property holds whether the line edit is read only.
- `isReadOnly` boolean

View File

@ -14,6 +14,7 @@ Napi::Object QLineEditWrap::init(Napi::Env env, Napi::Object exports) {
InstanceMethod("setPlaceholderText", &QLineEditWrap::setPlaceholderText),
InstanceMethod("setText", &QLineEditWrap::setText),
InstanceMethod("text", &QLineEditWrap::text),
InstanceMethod("setReadOnly", &QLineEditWrap::setReadOnly),
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLineEditWrap)
});
constructor = Napi::Persistent(func);
@ -55,6 +56,15 @@ Napi::Value QLineEditWrap::setText(const Napi::CallbackInfo& info) {
return env.Null();
}
Napi::Value QLineEditWrap::setReadOnly(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Boolean isReadOnly = info[0].As<Napi::Boolean>();
this->instance->setReadOnly(isReadOnly.Value());
return env.Null();
}
Napi::Value QLineEditWrap::text(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);

View File

@ -19,7 +19,8 @@ class QLineEditWrap : public Napi::ObjectWrap<QLineEditWrap>{
Napi::Value setText(const Napi::CallbackInfo& info);
Napi::Value text(const Napi::CallbackInfo& info);
Napi::Value setPlaceholderText(const Napi::CallbackInfo &info);
Napi::Value setReadOnly(const Napi::CallbackInfo &info);
QWIDGET_WRAPPED_METHODS_DECLARATION
};

View File

@ -30,6 +30,7 @@ export class QLineEdit extends NodeWidget {
this.setText.bind(this);
this.text.bind(this);
this.setPlaceholderText.bind(this);
this.setReadOnly.bind(this);
}
setText(text: string) {
text && this.native.setText(text);
@ -41,4 +42,7 @@ export class QLineEdit extends NodeWidget {
this.placeholderText = text;
this.native.setPlaceholderText(text);
}
setReadOnly(isReadOnly: boolean) {
this.native.setReadOnly(isReadOnly);
}
}