I want to create Dynamic Text Input in QtQuick1.1



  • Hi
    i am new in Qt ,I want to create Dynamic Text input , where number of text input fields are changing according to some condition. so i have created TextInput using Qt.createQmlObject() ,but how to get data from different text input which i have created Dynamically . I am using QtQuick 1.1

    import QtQuick 1.1
    import "Styling.js" as Style
    import "GRScript.js" as Script
    import "MenuList"
    
    Rectangle{
        id:startnodeFrame
        anchors.fill: parent
        property alias notetext: txtnote.text;
        property alias linktext: txtlinkid.text;
        property alias iconImage: iconid.source;
        property string imageType:"Caution"
    
        property string textString
        property string textInput
        property string editText: "import QtQuick 1.1;Row{ spacing: 10;Text {id: testString;text: '"+textString+"'}Rectangle{id:recTextInput;height:"+textInput+".height ;width: "+textInput+".width+100; border.color: \"black\";TextInput {id:"+textInput+";focus: true;height: 15;cursorPosition: 0}}}"
    Component.onCompleted:
        {
            textString="Hello"
            textInput="textinputid2"
            Qt.createQmlObject(editText, columnId, "dynamicObject")
           textString="world"
            textInput="textinputid1"
            var obj=Qt.createQmlObject(editText,columnId, "dynamicObject")
            if(imageType=="Caution")
            {
                iconImage="PopUp/warning-icon.png"
            }
            else if(imageType=="Stopwatch")
                iconImage="PopUp/stopwatchred.png"
            else
                iconImage=""
    
        }
        Keys.onUpPressed:
        {
            Script.asciiCodedrecrement();
        }
        Keys.onRightPressed:
        {
            Script.moveRight();
        }
        Keys.onLeftPressed:
        {
            Script.moveLeft();
        }
        Keys.onDownPressed:
        {
            Script.asciiCodeincrement();
        }
        Rectangle{
            id: title
            anchors.top: startnodeFrame.top
    
            color: Style.blue.background
            width: parent.width
            height: 20
            Text {
                id: txttitle
                text: qsTr("Guided Routine")
                color: Style.blue.foreground
            }
        }
    
        Rectangle{
            id:recstring
            anchors.top: title.bottom
            anchors.topMargin: 3
            width: parent.width-2
            height: parent.height-50
            border.color: Style.blue.background
            border.width: 3
            Rectangle{
                id:subTitle
                x:4
                anchors.top: recstring.top
                anchors.margins: 5
                width: parent.width-8
                height: 20
                color: Style.grey.background
                Text {
                    id: subTitleTxt
                    text: qsTr("SubHeading")
                }
    
            }
           
            Rectangle{
                id:displayarea
                anchors.top:subTitle.bottom
                x:4
                anchors.topMargin: 2
               Column{
                    anchors.fill: parent
                    id:columnId
                    spacing: 5
                }
            }
        }
    
    
        Row {
            id:rowid
            anchors.top: recstring.bottom
            anchors.topMargin: 3
            spacing: 1
            Rectangle{
                id:recnote
                height: 30
                width: 300
                color: Style.blue.background
                Row{
                    anchors.fill: parent
                    Image {
    
                        height: 30
                        width: 30
                        id: iconid
                    }
                    Text {
                        // anchors.centerIn: parent
                        id: txtnote
                        verticalAlignment: Text.AlignVCenter
                        text: qsTr("Note for u")
                        color: Style.blue.foreground
                    }
                }
    
            }
    
    
    
            Rectangle{
                id:reclinkid
                height: 30
                width: 98
                color: Style.blue.background
                //border.width: 3
                Text {
                    id: txtlinkid
                    anchors.centerIn: parent
                    text: qsTr("   Link Id")
                    color: Style.blue.foreground
                }
            }
        }
    
    }
    }
    

    Edited - Please follow Markdown syntax rules - p3c0



  • @yousuf said:

    Qt.createQmlObject

    I think you must use Qt.createComponent(url) and connect some signals etc.

    But you can store your componets in array like this:
    Rectangle{
    id:startnodeFrame
    property variant texts_objects: { }
    property string editText: "import QtQuick 1.1;Row{ property alias text: " + textInput + ".text; spacing: 10........"
    .............
    var text_data = {}
    text_data["textinputid1"] =Qt.createQmlObject(editText,columnId, "dynamicObject")
    .....
    text_data["textinputid2"] = Qt.createQmlObject(editText, columnId, "dynamicObject")
    .......
    startnodeFrame.texts_objects = text_data;

    After all using
    for(var text_prop in texts_objects)
    console.debug("Text of " + text_prop + texts_objects[text_prop].text)

    Or

      console.debug( "text of textinputid2 is: " +  texts_objects.textinputid2.text)

  • Moderators

    Hi,

    AFAIK you can't assign an id at runtime. If you use createQmlObject, IMO, the only way would be to access it using children property. Not sure if that works in QtQuick 1.1 (used it long way back).
    For something similar in QtQuick 2.x

    import QtQuick 2.3
    
    Rectangle {
        id: rect
        width: 200
        height: 200
    
        MouseArea {
            anchors.fill: parent
            onClicked: {
                var newObject = Qt.createQmlObject('import QtQuick 2.0; Rectangle {color: "red"; width: 50; height: 50; Text { text: "sample" }}',
                    rect, "dynamicSnippet1");
                console.log(newObject.color) //to access the Rectangle's properties
                console.log(newObject.children[0].text) //to access the Text's properties
            }
        }
    }
    

    Check if it works in QtQuick 1.x


  • Moderators

    @jalomic the new forum's editor follows Markdown syntax rules. So to post a code block you can encapsulate it inside ``` (3 backticks symbol)


  • Moderators

    @yousuf If you are new to Qt, I highly recommend using Qt Quick 2 instead.

    1.1 is very old technology, and it's deprecated now.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.