我在小部件中创建了一个 UI,并向其中添加了一个 edittext 控件和一个 pushButton 控件。在 QML 文件中,我有一个 TextInput 控件。我能够在 QML 中显示小部件控件。现在,我想将 QML 中的 EditText 控件文本设置为单击 Widget 的 pushButton 时在该控件内部的 edittext 控件中的文本。单击按钮时,我想将文本从 editText 发送到 QML TextInput。
这怎么可能。
我使用以下内容在 QML 中注册和使用 Widget。main.cpp 文件--->
qmlRegisterType<WidgetContainer>("MyWidget", 1, 0, "MyWidget");
QML 文件内容:
import QtQuick 1.1
import MyWidget 1.0
Rectangle {
width: 360
height: 360
color: "gray"
TextInput {
id: textInput1
x: 10
y: 10
width: 100
height: 100
color: "black"
cursorVisible: true
text: widget.getText()
}
MyWidget {
id: widget
x:10;
y:70
width: 180;
height: 150
text: "Widget text"
}
}