(→How to) |
|||
| Line 11: | Line 11: | ||
[[SDK/Docs/1.1/Getting_started_with_the_MeeGo_SDK_for_Linux|Install the MeeGo SDK]] first. Alternatively, you could just install the <code>meego-sdk-qt-creator</code> and <code>meego-sdk-qt</code> packages (see [[SDK/Docs/1.1/Getting_started_with_the_MeeGo_SDK_for_Linux|the same page]] for the location of the repos). | [[SDK/Docs/1.1/Getting_started_with_the_MeeGo_SDK_for_Linux|Install the MeeGo SDK]] first. Alternatively, you could just install the <code>meego-sdk-qt-creator</code> and <code>meego-sdk-qt</code> packages (see [[SDK/Docs/1.1/Getting_started_with_the_MeeGo_SDK_for_Linux|the same page]] for the location of the repos). | ||
| - | I'm using Fedora 13 Linux | + | I'm using Fedora 13 Linux, and have run the application on Fedora 13 and MeeGo 1.1. |
== How to == | == How to == | ||
| Line 22: | Line 22: | ||
* <code>Keys</code>, for connecting key presses to actions (e.g. to submit data entered in input elements) | * <code>Keys</code>, for connecting key presses to actions (e.g. to submit data entered in input elements) | ||
| - | === Create the QML application === | + | === Create the QML application with basic input elements === |
| - | + | <ol> | |
| - | + | <li>In the Qt Creator Welcome screen, click ''Create Project''.</li> | |
| - | + | ||
| + | <li>Select '''Qt Quick Project''' and '''QML Application''', then click ''Choose''.</li> | ||
| + | |||
| + | <li>Enter a name for the project (e.g. '''key-nav'''), then click ''Next'' and ''Finish''.</li> | ||
| + | |||
| + | <li>Edit the <code>key-nav.qml</code> file, which contains the main UI definition. The first version just displays three input elements: | ||
| + | <ol> | ||
| + | <li>A single line text edit box for a name.</li> | ||
| + | <li>A drop-down list of countries.</li> | ||
| + | <li>A button to submit the input data.</li> | ||
| + | <li>A label to display a greeting message based on the name and selected country.</li> | ||
| + | </ol> | ||
| + | This is what the QML looks like for this: | ||
| + | <pre> | ||
| + | import Qt 4.7 | ||
| + | |||
| + | Rectangle { | ||
| + | id: window | ||
| + | width: 600 | ||
| + | height: 300 | ||
| + | |||
| + | ListModel { | ||
| + | id: countries | ||
| + | |||
| + | ListElement { | ||
| + | name: "Finland" | ||
| + | } | ||
| + | ListElement { | ||
| + | name: "United Kingdom" | ||
| + | } | ||
| + | ListElement { | ||
| + | name: "USA" | ||
| + | } | ||
| + | } | ||
| + | |||
| + | Column { | ||
| + | anchors.left: parent.left | ||
| + | anchors.leftMargin: 10 | ||
| + | |||
| + | anchors.top: parent.top | ||
| + | anchors.topMargin: 10 | ||
| + | |||
| + | spacing: 20 | ||
| + | width: 180 | ||
| + | |||
| + | Row { | ||
| + | spacing: 10 | ||
| + | width: parent.width | ||
| + | |||
| + | Text { | ||
| + | text: "Name:" | ||
| + | } | ||
| + | |||
| + | TextInput { | ||
| + | id: nameInput | ||
| + | |||
| + | maximumLength: 30 | ||
| + | width: maximumLength * 10 | ||
| + | focus: true | ||
| + | fillColor: "darkgrey" | ||
| + | } | ||
| + | } | ||
| + | |||
| + | Row { | ||
| + | spacing: 10 | ||
| + | height: 60 | ||
| + | width: parent.width | ||
| + | |||
| + | Text { | ||
| + | text: "Country:" | ||
| + | } | ||
| + | |||
| + | ListView { | ||
| + | id: countrySelector | ||
| + | |||
| + | width: parent.width | ||
| + | height: parent.height | ||
| + | model: countries | ||
| + | highlight: Rectangle { | ||
| + | color: "darkgrey" | ||
| + | radius: 5 | ||
| + | } | ||
| + | delegate: Item { | ||
| + | width: parent.width | ||
| + | anchors.horizontalCenter: parent.horizontalCenter | ||
| + | height: 20 | ||
| + | Text { text: name } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | Row { | ||
| + | width: parent.width | ||
| + | height: 20 | ||
| + | |||
| + | Rectangle { | ||
| + | id: submitButton | ||
| + | |||
| + | width: parent.width | ||
| + | height: parent.height | ||
| + | color: "darkgrey" | ||
| + | radius: 5 | ||
| + | |||
| + | Text { | ||
| + | text: "Submit" | ||
| + | anchors.horizontalCenter: parent.horizontalCenter | ||
| + | anchors.verticalCenter: parent.verticalCenter | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | Row { | ||
| + | width: parent.width | ||
| + | height: 20 | ||
| + | |||
| + | Text { | ||
| + | id: greeting | ||
| + | text: "the greeting will be here" | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | </pre> | ||
| + | (I made no attempt at modularisation here, but kept everything in one file to make the explanations simpler. Also, this isn't usable at all yet.) | ||
| + | </li> | ||
| + | |||
| + | </ol> | ||
Contents |
This tutorial explains how to make a QML user interface entirely navigable by keyboard.
If you don't know anything about QML, reading the introductory Qt/QML documentation might be helpful.
Install the MeeGo SDK first. Alternatively, you could just install the meego-sdk-qt-creator and meego-sdk-qt packages (see the same page for the location of the repos).
I'm using Fedora 13 Linux, and have run the application on Fedora 13 and MeeGo 1.1.
You basically need to create a QML application with some input elements to start with.
You then add keyboard navigation using the following QML elements:
KeyNavigation, for defining paths between pairs of UI elements (e.g. to move between input elements)
Keys, for connecting key presses to actions (e.g. to submit data entered in input elements)
key-nav.qml file, which contains the main UI definition. The first version just displays three input elements:
This is what the QML looks like for this:
import Qt 4.7
Rectangle {
id: window
width: 600
height: 300
ListModel {
id: countries
ListElement {
name: "Finland"
}
ListElement {
name: "United Kingdom"
}
ListElement {
name: "USA"
}
}
Column {
anchors.left: parent.left
anchors.leftMargin: 10
anchors.top: parent.top
anchors.topMargin: 10
spacing: 20
width: 180
Row {
spacing: 10
width: parent.width
Text {
text: "Name:"
}
TextInput {
id: nameInput
maximumLength: 30
width: maximumLength * 10
focus: true
fillColor: "darkgrey"
}
}
Row {
spacing: 10
height: 60
width: parent.width
Text {
text: "Country:"
}
ListView {
id: countrySelector
width: parent.width
height: parent.height
model: countries
highlight: Rectangle {
color: "darkgrey"
radius: 5
}
delegate: Item {
width: parent.width
anchors.horizontalCenter: parent.horizontalCenter
height: 20
Text { text: name }
}
}
}
Row {
width: parent.width
height: 20
Rectangle {
id: submitButton
width: parent.width
height: parent.height
color: "darkgrey"
radius: 5
Text {
text: "Submit"
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
}
}
}
Row {
width: parent.width
height: 20
Text {
id: greeting
text: "the greeting will be here"
}
}
}
}
(I made no attempt at modularisation here, but kept everything in one file to make the explanations simpler. Also, this isn't usable at all yet.)