Search code examples
qmlqt6

Qt/QML Focus with Nested Views


I have a StackView. In that I open a SplitView. The SplitView contains two parts. In one part I have a TextField.

When I open the SplitView the focus shall be put on the TextField.

I tried many things: focus:true or forceActiveFocus(). I have no ideas anymore. Maybe someone could give me a hint.


Solution

  • The solution is pretty simple:

    Component.onCompleted: {
        Qt.callLater(correctFocus)
    }
    
    function correctFocus () {
        callTextField.forceActiveFocus();
    }