Solved TextInput with persistent focus
-
Hello,
I have following qml file:
import QtQuick 2.7 import QtQuick.Controls 2.0 import QtQuick.Controls.Styles 1.4 Rectangle { id: applicationWindow1 visible: true width: 640 height: 480 TextField { id: textInput1 width: 193 height: 130 anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter anchors.left: parent.left anchors.leftMargin: 193 anchors.top: parent.top anchors.topMargin: 130 focus: true text: qsTr("Text Input") font.pixelSize: 12 } Button { id: button1 y: 403 text: qsTr("Backspace") anchors.bottom: parent.bottom anchors.bottomMargin: 37 anchors.left: parent.left anchors.leftMargin: 257 onClicked: { console.log(textInput1.text.length) textInput1.remove(textInput1.text.length-1, textInput1.text.length) } } Component.onCompleted: { textInput1.forceActiveFocus(Qt.OtherFocusReason) } }
I would like to keep keyboard focus inside the TextInput even if the "Backspace" button was pressed. Do you have any idea/hints how to achieve this?
-
You can set the desired focusPolicy. For example:
Button { focusPolicy: Qt.NoFocus } // no focus at all Button { focusPolicy: Qt.TabFocus } // allow tab focus, but not click focus
-
Hello jpnurmi :-),
Thank you for the reply,
I think, that this is something what I was looking for.
Thank you :)