example 'meshtastic': sync Qt6 QML

This commit is contained in:
pls.153 2024-07-22 16:36:22 +02:00
parent 536a722822
commit 515cfc951e
2 changed files with 12 additions and 7 deletions

View file

@ -3,32 +3,36 @@ import QtQuick
Rectangle { Rectangle {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
width: 12 width: 12
height: 22 height: 25
color: (level > 15) ? "#f0f0f0" : "yellow" color: (level > 15) ? "#f0f0f0" : "yellow"
radius: 2 radius: 2
border.width: 1 border.width: 1
border.color: "#808080" border.color: "#808080"
property int level: 0 property string voltage
property string level
function percent() { return parseInt(level, 10) }
Rectangle { Rectangle {
x: 1 x: 1
width: parent.width - 2 width: parent.width - 2
height: (parent.height - 2) * level / 100 height: (parent.height - 2) * percent() / 100
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.bottomMargin: 1 anchors.bottomMargin: 1
color: (level > 15) ? "#28c940" : "#ff5f57" color: (percent() > 15) ? "#28c940" : "#ff5f57"
} }
Text { Text {
x: -4 - paintedWidth x: -4 - paintedWidth
height: parent.height height: parent.height
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
font.pixelSize: 12 horizontalAlignment: Text.AlignRight
font.pixelSize: 11
font.family: fontText.name font.family: fontText.name
font.weight: Font.DemiBold font.weight: Font.DemiBold
color: "white" color: "white"
text: level + "%" text: voltage + "\n" + level
} }
} }

View file

@ -49,7 +49,7 @@ Rectangle {
// hack to define all model key _types_ // hack to define all model key _types_
ListElement { ListElement {
name: ""; ini: false; hwModel: ""; batteryLevel: 0; current: false name: ""; ini: false; hwModel: ""; voltage: ""; batteryLevel: ""; current: false
} }
function addRadio(radio) { function addRadio(radio) {
@ -109,6 +109,7 @@ Rectangle {
Rad.BatteryLevel { Rad.BatteryLevel {
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: 14 anchors.rightMargin: 14
voltage: model.voltage
level: model.batteryLevel level: model.batteryLevel
visible: !model.ini visible: !model.ini
} }