Você pode fazer isso usando o QtSystemInfo que está no qtdeclarative5-systeminfo-plugin package.
Existeumademonstraçãomaiscompletado
import QtQuick 2.0
import QtSystemInfo 5.0
import Ubuntu.Components 0.1
MainView {
id: root
width: units.gu(50)
height: units.gu(75)
Page {
id: home
visible: true
title: "Battery Info"
BatteryInfo {
id: batinfo
property real percentage: 0
monitorRemainingCapacity: true
monitorChargingState: true
onRemainingCapacityChanged: {
var battery = 0
batinfo.percentage = (100/batinfo.maximumCapacity(battery)*batinfo.remainingCapacity(battery)).toFixed(1)
level.text = percentage + "%"
}
}
UbuntuShape {
id: image
anchors.bottom: level.top
anchors.horizontalCenter: level.horizontalCenter
anchors.margins: units.gu(2)
image: Image {
// here you would obviously want differet icons based on the percentage, but I'm lazy
source: Qt.resolvedUrl("/usr/share/icons/ubuntu-mobile/status/scalable/battery_full.svg")
}
}
Label {
id: level
anchors.centerIn: parent
fontSize: "x-large"
}
}
}