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. TextInput and TextEdit cursor keeps blinking when item looses focus
Forum Updated to NodeBB v4.3 + New Features

TextInput and TextEdit cursor keeps blinking when item looses focus

Scheduled Pinned Locked Moved QML and Qt Quick
5.4qmllinuxvirtual keyboar
1 Posts 1 Posters 2.9k Views 1 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.
  • P Offline
    P Offline
    PhTe
    wrote on last edited by
    #1

    I have two text input fields and want to switch from the first to the second if the user pressed the enter key.
    Since i use a virtual keyboard which is not sending key events i have to resolve this with the onTextChanged handler.
    The switch itself is not the problem, but the cursor in the first field keeps blinking even if the item looses focus. So after i switch from first to second input, both fields show a blinking cursor but only the second input takes the key inputs.
    It is a little bit confusing if you have 2 inputs and you dont know where you are typing now, so im looking for a solution to hide the cursor if the item has not the focus.

    My first item looks like this

    TextInput {
        id: firstInput
    
        onTextChanged: {
            /* Check if enter key was pressed (charCode 10), remove it from the text, update 
             the item value and send accepted event*/
            if(text.length > 0 && text.charCodeAt(text.length-1) === 10) {
                var txt = text.substring(0,text.length-1);
                txt = txt.trim();
                text = txt;
                console.log("emit accepted signal");
                accepted();
            }
        }
    
        onFocusChanged: {
            console.log("Focus changed to "+focus);
        }
    
        onCursorVisibleChanged: {
            console.log("Cursor visible changed to "+cursorVisible);
        }
    
        onAccepted: {
             console.log("Force focus to secondInput");
             secondInput.forceActiveFocus();
        }
    }
    

    And the debug output looks like

    qml: emit accepted signal
    qml: Force focus to secondInput
    qml: Cursor visible changed to false
    qml: Focus changed to false
    qml: Cursor visible changed to true
    

    You can see that the cursor is set to false and than, after the item looses focus, it is set back to true. I tried to set the cursorVisible property in the onFocusChanged function to false, but it is ignored.

    So does anyone know how to fix this?

    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