Qt Quick Controls - Wearable Demo
Demonstrates an application launcher designed for wearable devices.
The Wearable Demo consists of an application launcher and a collection of small and simple example applications aimed at wearable devices.
Structure
The main .qml file, wearable.qml
, consists of an ApplicationWindow, a StackView for a stack-based navigation model, and buttons for interactive navigation.
QQC2.ApplicationWindow { id: window ... header: NaviButton { id: homeButton ... onClicked: stackView.pop(null) } footer: NaviButton { id: backButton ... onClicked: stackView.pop() } QQC2.StackView { id: stackView ... onLaunched: stackView.push(page) } } DemoMode { stackView: stackView } DemoModeIndicator { id: demoModeIndicator y: settings.demoMode ? -height : -height * 2 anchors.horizontalCenter: parent.horizontalCenter height: header.height z: window.header.z + 1 } MouseArea { enabled: settings.demoMode anchors.fill: parent onClicked: { // Stop demo mode and return to the launcher page. settings.demoMode = false stackView.pop(null) } } }
Styling
The demo uses a custom Qt Quick Controls 2 style embedded into the demo's resources. The custom style is implemented for a few controls only, as it is specific to this particular demo. It uses a singleton type for various styling attributes, such as fonts and colors.
qml/Style/PageIndicator.qml
qml/Style/Slider.qml
qml/Style/Switch.qml
qml/Style/UIStyle.qml
The style is applied in main()
in wearable.cpp
:
QQuickStyle::setStyle(QStringLiteral("qrc:/qml/Style"));
The main benefit of using the built-in styling system is that the style selection is fully transparent to the application code. There is no need to import a specific folder that contains the styled controls. This way, the application can be run with other styles too.
Custom Type
The demo application contains a custom button type implemented in qml/NaviButton.qml
. The navigation button is used as a home and back button in wearable.qml
. NaviButton
extends the AbstractButton type with properties that control the slide in and slide out transitions and the button image.
QQC2.AbstractButton { id: button property int edge: Qt.TopEdge property alias imageSource: image.source contentItem: Image { id: image ... } background: Rectangle { ... } transform: Translate { Behavior on y { NumberAnimation { } } y: enabled ? 0 : edge === Qt.TopEdge ? -button.height : button.height } }
Icons
The demo ships a custom icon theme. The icons are bundled into the :/icons
folder in the application's resources. The index.theme
file lists the contents of the icon theme:
[Icon Theme] Name=Wearable Comment=Qt Quick Controls 2 Wearable Demo Icon Theme Directories=36x36,36x36@2 [36x36] Size=36 Type=Fixed [36x36@2] Size=36 Scale=2 Type=Fixed
Finally, the icon theme is selected in main()
:
QIcon::setThemeName(QStringLiteral("wearable"));
The icons are used on the Launcher Page, which is presented below. See Icons in Qt Quick Controls 2 for more details about icons and themes.
Launcher Page
The application launcher is implemented using a circular PathView in LauncherPage.qml
. Each application is in a separate .qml file, which is added to the ListModel on the launcher page.
PathView { id: circularView signal launched(string page) ... model: ListModel { ListElement { title: qsTr("World Clock") icon: "worldclock" page: "WorldClock/WorldClockPage.qml" } ... ListElement { title: qsTr("Settings") icon: "settings" page: "Settings/SettingsPage.qml" } } delegate: QQC2.RoundButton { ... icon.width: 36 icon.height: 36 icon.name: model.icon ... onClicked: { if (PathView.isCurrentItem) circularView.launched(Qt.resolvedUrl(page)) else circularView.currentIndex = index } } ... }
Applications
The applications are designed for touch input based on what input methods or communication means are typically offered by wearable devices.
Most applications have their own JavaScript files that act as dummy application backends. They illustrate fetching external data and help manipulating or converting the data. In the Navigation
and Weather
applications, data acquisition is implemented using XMLHttpRequest to read from local files. These files were generated by storing responses from remote servers in JSON format. This code can be easily modified to acquire data from remote servers.
Navigation
This application displays a walking route from source to destination. This route information is obtained using the REST API provided by https://www.openstreetmap.org/. The API response is in JSON format, which is parsed using JavaScript by the application. Currently, it is not possible to specify the source and destination from within the application, but it can be added based on the device's capabilities. For example, user input could be implemented as screens with input fields, or can be communicated over Bluetooth/Wifi from a paired application running on another device such as a smart phone or PC.
Weather
This application displays weather information such as temperature, sunrise and sunset times, air pressure, and so on. This information is obtained from https://openweathermap.org/ using its REST API. The API response is in JSON format, which is parsed using JavaScript by the application. This application can also be modified by adding screens to obtain weather data for a given location.
World Clock
This application displays a world clock for different cities. As of now, the list of cities is hard-coded in the application, but that can be changed based on the input capabilities of the device.
Others
The remaining applications return static data for now, but they can be modified to process response data obtained from respective services.
Running the Example
To run the example from Qt Creator, open the Welcome mode and select the example from Examples. For more information, visit Building and Running an Example.
Files:
- wearable/qml/Alarms/AlarmsPage.qml
- wearable/qml/DemoMode.qml
- wearable/qml/DemoModeIndicator.qml
- wearable/qml/Fitness/FitnessPage.qml
- wearable/qml/Fitness/fitness.js
- wearable/qml/LauncherPage.qml
- wearable/qml/NaviButton.qml
- wearable/qml/Navigation/NavigationPage.qml
- wearable/qml/Navigation/RouteElement.qml
- wearable/qml/Navigation/navigation.js
- wearable/qml/Notifications/NotificationsPage.qml
- wearable/qml/Notifications/notifications.js
- wearable/qml/Settings/SettingsPage.qml
- wearable/qml/Settings/images/demo-mode.svg
- wearable/qml/Settings/images/theme.svg
- wearable/qml/Style/PageIndicator.qml
- wearable/qml/Style/Slider.qml
- wearable/qml/Style/Switch.qml
- wearable/qml/Style/UIStyle.qml
- wearable/qml/Style/qmldir
- wearable/qml/SwipeViewPage.qml
- wearable/qml/Weather/WeatherPage.qml
- wearable/qml/Weather/weather.js
- wearable/qml/WorldClock/Clock.qml
- wearable/qml/WorldClock/WorldClockPage.qml
- wearable/wearable.cpp
- wearable/wearable.pro
- wearable/wearable.qml
- wearable/wearable.qrc
Images:
- wearable/icons/wearable/36x36/alarms.png
- wearable/icons/wearable/36x36/fitness.png
- wearable/icons/wearable/36x36/navigation.png
- wearable/icons/wearable/36x36/notifications.png
- wearable/icons/wearable/36x36/settings.png
- wearable/icons/wearable/36x36/weather.png
- wearable/icons/wearable/36x36/worldclock.png
- wearable/icons/wearable/36x36@2/alarms.png
- wearable/icons/wearable/36x36@2/fitness.png
- wearable/icons/wearable/36x36@2/navigation.png
- wearable/icons/wearable/36x36@2/notifications.png
- wearable/icons/wearable/36x36@2/settings.png
- wearable/icons/wearable/36x36@2/weather.png
- wearable/icons/wearable/36x36@2/worldclock.png
- wearable/images/back.png
- wearable/images/back@2x.png
- wearable/images/back@3x.png
- wearable/images/back@4x.png
- wearable/images/background-dark.png
- wearable/images/background-light.png
- wearable/images/home.png
- wearable/images/home@2x.png
- wearable/images/home@3x.png
- wearable/images/home@4x.png
- wearable/qml/Fitness/images/man-running-dark.png
- wearable/qml/Fitness/images/man-running-dark@2x.png
- wearable/qml/Fitness/images/man-running-light.png
- wearable/qml/Fitness/images/man-running-light@2x.png
- wearable/qml/Fitness/images/man-walking-dark.png
- wearable/qml/Fitness/images/man-walking-dark@2x.png
- wearable/qml/Fitness/images/man-walking-light.png
- wearable/qml/Fitness/images/man-walking-light@2x.png
- wearable/qml/Navigation/images/end.png
- wearable/qml/Navigation/images/end@2x.png
- wearable/qml/Navigation/images/leftturn-dark.png
- wearable/qml/Navigation/images/leftturn-dark@2x.png
- wearable/qml/Navigation/images/leftturn-light.png
- wearable/qml/Navigation/images/leftturn-light@2x.png
- wearable/qml/Navigation/images/marker.png
- wearable/qml/Navigation/images/navigation-dark.png
- wearable/qml/Navigation/images/navigation-dark@2x.png
- wearable/qml/Navigation/images/navigation-light.png
- wearable/qml/Navigation/images/navigation-light@2x.png
- wearable/qml/Navigation/images/rightturn-dark.png
- wearable/qml/Navigation/images/rightturn-dark@2x.png
- wearable/qml/Navigation/images/rightturn-light.png
- wearable/qml/Navigation/images/rightturn-light@2x.png
- wearable/qml/Navigation/images/start.png
- wearable/qml/Navigation/images/start@2x.png
- wearable/qml/Navigation/images/straight-dark.png
- wearable/qml/Navigation/images/straight-dark@2x.png
- wearable/qml/Navigation/images/straight-light.png
- wearable/qml/Navigation/images/straight-light@2x.png
- wearable/qml/Navigation/images/uturn.png
- wearable/qml/Navigation/images/uturn@2x.png
- wearable/qml/Notifications/images/avatarf-dark.png
- wearable/qml/Notifications/images/avatarf-dark@2x.png
- wearable/qml/Notifications/images/avatarf-light.png
- wearable/qml/Notifications/images/avatarf-light@2x.png
- wearable/qml/Notifications/images/avatarm-dark.png
- wearable/qml/Notifications/images/avatarm-dark@2x.png
- wearable/qml/Notifications/images/avatarm-light.png
- wearable/qml/Notifications/images/avatarm-light@2x.png
- wearable/qml/Notifications/images/missedcall-dark.png
- wearable/qml/Notifications/images/missedcall-dark@2x.png
- wearable/qml/Notifications/images/missedcall-light.png
- wearable/qml/Notifications/images/missedcall-light@2x.png
- wearable/qml/Settings/images/bluetooth-dark.png
- wearable/qml/Settings/images/bluetooth-dark@2x.png
- wearable/qml/Settings/images/bluetooth-light.png
- wearable/qml/Settings/images/bluetooth-light@2x.png
- wearable/qml/Settings/images/brightness-dark.png
- wearable/qml/Settings/images/brightness-dark@2x.png
- wearable/qml/Settings/images/brightness-light.png
- wearable/qml/Settings/images/brightness-light@2x.png
- wearable/qml/Settings/images/demo-mode-dark.png
- wearable/qml/Settings/images/demo-mode-dark@2x.png
- wearable/qml/Settings/images/demo-mode-light.png
- wearable/qml/Settings/images/demo-mode-light@2x.png
- wearable/qml/Settings/images/demo-mode-white.png
- wearable/qml/Settings/images/demo-mode-white@2x.png
- wearable/qml/Settings/images/theme-dark.png
- wearable/qml/Settings/images/theme-dark@2x.png
- wearable/qml/Settings/images/theme-light.png
- wearable/qml/Settings/images/theme-light@2x.png
- wearable/qml/Settings/images/wifi-dark.png
- wearable/qml/Settings/images/wifi-dark@2x.png
- wearable/qml/Settings/images/wifi-light.png
- wearable/qml/Settings/images/wifi-light@2x.png
- wearable/qml/Weather/images/humidity-dark.png
- wearable/qml/Weather/images/humidity-dark@2x.png
- wearable/qml/Weather/images/humidity-light.png
- wearable/qml/Weather/images/humidity-light@2x.png
- wearable/qml/Weather/images/pressure-dark.png
- wearable/qml/Weather/images/pressure-dark@2x.png
- wearable/qml/Weather/images/pressure-light.png
- wearable/qml/Weather/images/pressure-light@2x.png
- wearable/qml/Weather/images/sunrise-dark.png
- wearable/qml/Weather/images/sunrise-dark@2x.png
- wearable/qml/Weather/images/sunrise-light.png
- wearable/qml/Weather/images/sunrise-light@2x.png
- wearable/qml/Weather/images/sunset-dark.png
- wearable/qml/Weather/images/sunset-dark@2x.png
- wearable/qml/Weather/images/sunset-light.png
- wearable/qml/Weather/images/sunset-light@2x.png
- wearable/qml/Weather/images/temperature-dark.png
- wearable/qml/Weather/images/temperature-dark@2x.png
- wearable/qml/Weather/images/temperature-light.png
- wearable/qml/Weather/images/temperature-light@2x.png
- wearable/qml/Weather/images/wind-dark.png
- wearable/qml/Weather/images/wind-dark@2x.png
- wearable/qml/Weather/images/wind-light.png
- wearable/qml/Weather/images/wind-light@2x.png
- wearable/qml/WorldClock/images/center.png
- wearable/qml/WorldClock/images/center@2x.png
- wearable/qml/WorldClock/images/clock-night.png
- wearable/qml/WorldClock/images/clock-night@2x.png
- wearable/qml/WorldClock/images/clock.png
- wearable/qml/WorldClock/images/second.png
- wearable/qml/WorldClock/images/second@2x.png
- wearable/qml/WorldClock/images/swissdaydial.png
- wearable/qml/WorldClock/images/swissdaydial@2x.png
- wearable/qml/WorldClock/images/swissdayhour.png
- wearable/qml/WorldClock/images/swissdayhour@2x.png
- wearable/qml/WorldClock/images/swissdayminute.png
- wearable/qml/WorldClock/images/swissdayminute@2x.png
- wearable/qml/WorldClock/images/swissnightdial.png
- wearable/qml/WorldClock/images/swissnightdial@2x.png
- wearable/qml/WorldClock/images/swissnighthour.png
- wearable/qml/WorldClock/images/swissnighthour@2x.png
- wearable/qml/WorldClock/images/swissnightminute.png
- wearable/qml/WorldClock/images/swissnightminute@2x.png
- wearable/qml/WorldClock/images/swissseconds.png
© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.