Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. I want to create Dynamic Text Input in QtQuick1.1
Forum Updated to NodeBB v4.3 + New Features

I want to create Dynamic Text Input in QtQuick1.1

Scheduled Pinned Locked Moved QML and Qt Quick
qtquickqml
5 Posts 4 Posters 2.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yousuf
    wrote on last edited by p3c0
    #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

    JKSHJ 1 Reply Last reply
    0
    • J Offline
      J Offline
      jalomic
      wrote on last edited by
      #2

      @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)
      
      p3c0P 1 Reply Last reply
      0
      • p3c0P Offline
        p3c0P Offline
        p3c0
        Moderators
        wrote on last edited by p3c0
        #3

        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

        157

        1 Reply Last reply
        0
        • J jalomic

          @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)
          
          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

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

          157

          1 Reply Last reply
          0
          • Y yousuf

            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

            JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            @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.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved