Merge pull request #30 from nodegui/feature/QTextEdit
Add textChange event for QPlainTextEdit
This commit is contained in:
commit
c0cc5da3a3
@ -30,4 +30,14 @@ QPlainTextEdit can access all the instance properties defined in [NodeWidget](ap
|
||||
|
||||
### Instance Methods
|
||||
|
||||
QPlainTextEdit can access all the instance methods defined in [NodeWidget](api/NodeWidget.md).
|
||||
QPlainTextEdit can access all the instance methods defined in [NodeWidget](api/NodeWidget.md).
|
||||
|
||||
#### [`plainTextEdit.setPlainText(text)`](https://doc.qt.io/qt-5/qplaintextedit.html#setPlainText)
|
||||
|
||||
Sets the given text to the plainTextEdit.
|
||||
|
||||
- `text` string
|
||||
|
||||
#### [`plainTextEdit.toPlainText()`](https://doc.qt.io/qt-5/qplaintextedit.html#toPlainText)
|
||||
|
||||
Returns the text of the text edit as plain text.
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "deps/spdlog/spdlog.h"
|
||||
#include <QPlainTextEdit>
|
||||
#include "src/cpp/core/NodeWidget/nodewidget.h"
|
||||
|
||||
@ -8,4 +9,13 @@ class NPlainTextEdit : public QPlainTextEdit, public NodeWidget
|
||||
NODEWIDGET_IMPLEMENTATIONS
|
||||
public:
|
||||
using QPlainTextEdit::QPlainTextEdit; //inherit all constructors of QPlainTextEdit
|
||||
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QObject::connect(this, &QPlainTextEdit::textChanged, [=]() {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
this->emitOnNode.Call({Napi::String::New(env, "textChanged")});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -12,6 +12,7 @@ Napi::Object QPlainTextEditWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
char CLASSNAME[] = "QPlainTextEdit";
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||
InstanceMethod("setPlainText",&QPlainTextEditWrap::setPlainText),
|
||||
InstanceMethod("toPlainText",&QPlainTextEditWrap::toPlainText),
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QPlainTextEditWrap)
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
@ -51,3 +52,9 @@ Napi::Value QPlainTextEditWrap::setPlainText(const Napi::CallbackInfo& info){
|
||||
this->instance->setPlainText(plainText.Utf8Value().c_str());
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QPlainTextEditWrap::toPlainText(const Napi::CallbackInfo &info){
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
return Napi::Value::From(env, this->instance->toPlainText().toStdString());
|
||||
}
|
||||
@ -19,5 +19,6 @@ class QPlainTextEditWrap : public Napi::ObjectWrap<QPlainTextEditWrap>{
|
||||
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
Napi::Value setPlainText(const Napi::CallbackInfo& info);
|
||||
Napi::Value toPlainText(const Napi::CallbackInfo &info);
|
||||
};
|
||||
|
||||
|
||||
13
src/demo.ts
13
src/demo.ts
@ -9,7 +9,8 @@ import {
|
||||
FlexLayout,
|
||||
QWidget,
|
||||
QIcon,
|
||||
QPlainTextEdit
|
||||
QPlainTextEdit,
|
||||
QPlainTextEditEvents
|
||||
} from "./index";
|
||||
|
||||
const path = require("path");
|
||||
@ -28,6 +29,7 @@ const lineEdit = new QLineEdit();
|
||||
lineEdit.setPlaceholderText("Enter your thoughts here");
|
||||
lineEdit.setObjectName("editable");
|
||||
|
||||
|
||||
const button = new QPushButton();
|
||||
button.setText("Push Push Push!");
|
||||
button.setObjectName("btn");
|
||||
@ -49,9 +51,17 @@ radioButton.setText("Roger that!");
|
||||
const rootView = new QWidget();
|
||||
rootView.setObjectName("root");
|
||||
rootView.setLayout(new FlexLayout());
|
||||
|
||||
const lineEditLabel = new QLabel();
|
||||
lineEditLabel.setInlineStyle("font-size: 12px;");
|
||||
lineEditLabel.setText("PlainTextEdit's bound Value");
|
||||
const textEdit = new QPlainTextEdit();
|
||||
textEdit.setPlainText("Hello");
|
||||
|
||||
textEdit.addEventListener(QPlainTextEditEvents.textChanged, (value: string) => {
|
||||
lineEditLabel.setText(textEdit.toPlainText());
|
||||
});
|
||||
|
||||
if (rootView.layout) {
|
||||
rootView.layout.addWidget(label);
|
||||
rootView.layout.addWidget(checkbox);
|
||||
@ -60,6 +70,7 @@ if (rootView.layout) {
|
||||
rootView.layout.addWidget(button);
|
||||
rootView.layout.addWidget(progressbar);
|
||||
rootView.layout.addWidget(textEdit);
|
||||
rootView.layout.addWidget(lineEditLabel);
|
||||
}
|
||||
|
||||
win.setCentralWidget(rootView);
|
||||
|
||||
@ -4,8 +4,10 @@ import { BaseWidgetEvents } from "../../core/EventWidget";
|
||||
import { NativeElement } from "../../core/Component";
|
||||
|
||||
export const QPlainTextEditEvents = Object.freeze({
|
||||
...BaseWidgetEvents
|
||||
...BaseWidgetEvents,
|
||||
textChanged: "textChanged",
|
||||
});
|
||||
|
||||
export class QPlainTextEdit extends NodeWidget {
|
||||
native: NativeElement;
|
||||
constructor(parent?: NodeWidget) {
|
||||
@ -20,8 +22,12 @@ export class QPlainTextEdit extends NodeWidget {
|
||||
this.parent = parent;
|
||||
// bind member functions
|
||||
this.setPlainText.bind(this);
|
||||
this.toPlainText.bind(this);
|
||||
}
|
||||
setPlainText(text: string | number) {
|
||||
this.native.setPlainText(`${text}`);
|
||||
}
|
||||
toPlainText() {
|
||||
return this.native.toPlainText();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user