How to make onEditingFinished available to individual TextInput elements reusing a common TextInput
-
I am new to
QML&Qt. I am trying to make multipleTextInputelements which can send their owntextwhenonEditingFinishedis triggered. Following is aTextInputitem that I have created inMyTextField.qml:MyTextField.qml
import QtQuick 2.5 import QtQuick.Controls 1.4 Item { implicitHeight: 200 implicitWidth: 1000 property alias inputMethodHints: myTextField.inputMethodHints property alias text: myTextField.text Rectangle { anchors.fill: parent radius: 40 } TextInput { id: myTextField objectName: "myTextField" anchors.fill: parent verticalAlignment: Text.AlignVCenter font.pixelSize: 300 color: 'white' signal qmlSignal(string msg) onEditingFinished: qmlSignal(text) //This works } }I am trying to use the above
TextInputelement in anotherqmlfile like below:SomeOtherPage.qml
Column { anchors.top: parent.top anchors.left: parent.left anchors.right: parent.right anchors.margins: theme.defaultMargin MyTextField { id: textfield1 objectName: "textfield1" anchors.left: parent.left anchors.right: parent.right text: qsTr("some text") signal qmlSignal11(string msg) onEditingFinished: qmlSignal11(text) //This doesn't work !! } MyTextField { id: textfield2 objectName: "textfield2" anchors.left: parent.left anchors.right: parent.right text: qsTr("some other text") signal qmlSignal22(string msg) onEditingFinished: qmlSignal22(text) //This doesn't work !! } }In
MyTextFieldblocks, QML doesn't allow me to useonEditingFinishedat all. Running the app complainsCannot assign to non-existent property "onEditingFinished"If I handle
onEditingFinishedfrom the parentTextInputI created, it works fine & sends the signal to myC++class. But I am trying to useonEditingFinishedintextfield1&textfield2. Qml reports thatonEditingFinishedproperty is not available. How I can makeonEditingFinishedavailable intextfield1&textfield2so that I send the text of each unique textfield I create. -
Hi!
MyTextItem.qml
import QtQuick 2.7 import QtQuick.Controls 2.0 Rectangle { id: myTextItem radius: 10 width: 100 height: 30 signal editingFinished() TextInput { anchors.margins: 5 anchors.fill: parent text: "Hallo" onEditingFinished: myTextItem.editingFinished() } }main.qml
import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.0 ApplicationWindow { visible: true width: 640 height: 480 title: qsTr("Hello World") Column { spacing: 10 MyTextItem { color: "plum" onEditingFinished: console.log("finished plum") } MyTextItem { color: "lime" onEditingFinished: console.log("finished lime") } } } -
Hi!
MyTextItem.qml
import QtQuick 2.7 import QtQuick.Controls 2.0 Rectangle { id: myTextItem radius: 10 width: 100 height: 30 signal editingFinished() TextInput { anchors.margins: 5 anchors.fill: parent text: "Hallo" onEditingFinished: myTextItem.editingFinished() } }main.qml
import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Layouts 1.0 ApplicationWindow { visible: true width: 640 height: 480 title: qsTr("Hello World") Column { spacing: 10 MyTextItem { color: "plum" onEditingFinished: console.log("finished plum") } MyTextItem { color: "lime" onEditingFinished: console.log("finished lime") } } }@Wieland thanks a many lot. it works