PDA

View Full Version : How to shift focus from one text box to another?



TheIndependentAquarius
27th September 2013, 11:07
The code creates two input text boxes:



import QtQuick 1.0

Column
{
width: 500
height: 200

Text
{
id: userInfoTextA
focus: false
text: "Enter a value from 0 to 10:"
}

TextInput
{
id: userInputA
focus: true

anchors.left : userInfoTextA.right
anchors.leftMargin : 20

validator: IntValidator { bottom:0; top: 20 }

Keys.onReturnPressed:
{
console.log (userInputA.text)
}
}

Text
{
id: userInfoTextB
focus: false
text: "Enter a value from 10 to 20:"
}

TextInput
{
id: userInputB
focus: true

anchors.left : userInfoTextB.right
anchors.leftMargin : 20

validator: IntValidator { bottom:0; top: 20 }

Keys.onReturnPressed:
{
console.log (userInputB.text)
}
}
}



In the output window the focus, by default, is set to the text box A. How should I move the focus to text box B by:
- Keyboard

and

- Mouse
?

TheIndependentAquarius
30th September 2013, 08:44
From stackoverflow I came to know about key navigation for shifting focus through keyboard:
http://qt-project.org/doc/qt-4.8/qml-keynavigation.html
http://stackoverflow.com/a/19051908/462608