QTextField focus issue in QML



  • Hi friends,,

         I have used two text field,,if i click the button means that time two text field is visible,,but it is not foucsed in the first text field and cursor also not visible,, how to focus in the first text field and cursor visible in the text field in the first time,,so please give me some suggesstion,,
    

    Thanks,,


  • Moderators

    Hi,

    Set focus to true for the first TextField.



  • Hi,

     I give the Focus to true in the text field,,but first time cursor is not focused on the first text field,,If i click the text field means after every time it focused in the text field,,but First time it's not focused,,this is the problem,,please give me the suggesstion,,
    

    Thanks


  • Moderators

    Is there any other Item that takes the focus away ?
    May be you should try setting the focus in Component.onCompleted handler.



  • Hi,

    Try this, try to set the focus of second field only when first is filled,

    TextInput {
    id: passwordField
    focus:true
    cursorPosition: TextInput.AlignHCenter // Align as needed
    MouseArea{ // If Needed
    anchors.fill: parent
    onClicked: {
    passwordField.forceActiveFocus()
    }
    }

    }

    TextInput {
    id: passwordField1
    focus: (passwordField.text !== "")
    cursorPosition: TextInput.AlignHCenter // Align as needed
    MouseArea{ // If Needed
    anchors.fill: parent
    onClicked: {
    Qt.inputMethod.show()
    clear_field(false,true,true,false)
    passwordField1.forceActiveFocus()
    }
    }
    onActiveFocusChanged:{ // Focus Change Function if needed
    if(passwordField1.focus) {
    if(passwordField.textValue == "") {
    passwordField.forceActiveFocus()
    }
    }
    }
    }


Log in to reply
 

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