Solved How to make onEditingFinished available to individual TextInput elements reusing a common TextInput
-
I am new to
QML
&Qt
. I am trying to make multipleTextInput
elements which can send their owntext
whenonEditingFinished
is triggered. Following is aTextInput
item 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
TextInput
element in anotherqml
file 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
MyTextField
blocks, QML doesn't allow me to useonEditingFinished
at all. Running the app complainsCannot assign to non-existent property "onEditingFinished"
If I handle
onEditingFinished
from the parentTextInput
I created, it works fine & sends the signal to myC++
class. But I am trying to useonEditingFinished
intextfield1
&textfield2
. Qml reports thatonEditingFinished
property is not available. How I can makeonEditingFinished
available intextfield1
&textfield2
so 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") } } }
-
@Wieland thanks a many lot. it works