Add textChange event for QPlainTextEdit
This commit is contained in:
parent
65becffd52
commit
0151246d95
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "deps/spdlog/spdlog.h"
|
||||
#include <QPlainTextEdit>
|
||||
#include "src/cpp/core/NodeWidget/nodewidget.h"
|
||||
|
||||
@ -8,4 +9,14 @@ 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, [=]() {
|
||||
QString str = this->toPlainText();
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
this->emitOnNode.Call({Napi::String::New(env, "textChanged"), Napi::Value::From(env, str.toStdString())});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
12
src/demo.ts
12
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,8 +51,15 @@ 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(value);
|
||||
});
|
||||
|
||||
if (rootView.layout) {
|
||||
rootView.layout.addWidget(label);
|
||||
@ -60,6 +69,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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user