fix🐛: 修复显示的问题,更新button的功能

This commit is contained in:
Alvin Young 2024-12-02 17:51:21 +08:00
parent e4b0551e59
commit a6fa2fa5d3
7 changed files with 82 additions and 28 deletions

View File

@ -10,9 +10,6 @@ Window {
minimumHeight: 600 minimumHeight: 600
minimumWidth: 800 minimumWidth: 800
// color: "green" // color: "green"
GlobalProperties {
id: id_gp
}
MainPage { MainPage {
id: id_home_page id: id_home_page

View File

@ -33,15 +33,30 @@ Item {
} }
Button { Button {
Layout.preferredWidth: 100 id: button
text: "重新连接" text: "重新连接"
hoverEnabled: false Layout.preferredWidth: 100
Layout.preferredHeight: 50
font.pixelSize: id_gp.font_info_pixel_size font.pixelSize: id_gp.font_info_pixel_size
background: Rectangle { //
color: control.pressed ? "lightblue" : "blue" background: Rectangle {
border.color: "black" color: button.down ? id_gp.btn_pressedBackground :
button.hovered ? id_gp.btn_hoverBackground : id_gp.btn_normalBackground
border.color: id_gp.btn_borderColor
radius: 10 radius: 10
} }
// 使 Button hover
hoverEnabled: true
// MouseArea
MouseArea {
anchors.fill: parent
onPressed: button.background.color = id_gp.btn_pressedBackground
onReleased: button.background.color = button.hovered ? id_gp.btn_hoverBackground : id_gp.btn_normalBackground
onExited: button.background.color = id_gp.btn_normalBackground
}
onClicked: { onClicked: {
console.log("press butn") console.log("press butn")
} }

View File

@ -20,14 +20,15 @@ Item {
source: "qrc:/assets/img/terminal-box-fill.svg" source: "qrc:/assets/img/terminal-box-fill.svg"
smooth: true // 使 smooth: true // 使
asynchronous: true // asynchronous: true //
// 使 ColorOverlay SVG
ColorOverlay {
anchors.fill: parent
source: parent
color: id_gp.left_menu_non_lighlight_color // SVG
}
} }
// 使 ColorOverlay SVG
ColorOverlay {
anchors.fill: id_svg_icon_info_lb
source: id_svg_icon_info_lb
color: id_gp.left_menu_non_lighlight_color // SVG
}
Text { Text {
text: "芯片类型:" text: "芯片类型:"

View File

@ -8,11 +8,8 @@ Item {
Component { Component {
id: contactDelegate id: contactDelegate
// property int my_index: index
Rectangle { Rectangle {
width: 60; height: 60 width: 60; height: 60
anchors.left: parent.left //
anchors.leftMargin: 10 // 20
radius: 5 radius: 5
color: id_gp.left_menu_non_lighlight_color color: id_gp.left_menu_non_lighlight_color
MouseArea { MouseArea {
@ -100,6 +97,7 @@ Item {
id: id_view id: id_view
spacing: 10 spacing: 10
topMargin: 10 topMargin: 10
leftMargin: 10
anchors.fill: parent anchors.fill: parent
model: TestModels {} model: TestModels {}
delegate: contactDelegate delegate: contactDelegate
@ -108,18 +106,42 @@ Item {
snapMode: ListView.SnapToItem snapMode: ListView.SnapToItem
onCurrentIndexChanged: { onCurrentIndexChanged: {
// console.log("2 left_menu_index", id_gp.left_menu_index_now) // console.log("2 left_menu_index", id_gp.left_menu_index_now)
itemAtIndex(id_gp.left_menu_index_now).color = id_gp.left_menu_lighlight_color
itemAtIndex(id_gp.left_menu_index_last).color = id_gp.left_menu_non_lighlight_color itemAtIndex(id_gp.left_menu_index_last).color = id_gp.left_menu_non_lighlight_color
itemAtIndex(id_gp.left_menu_index_now).color = id_gp.left_menu_lighlight_color
} }
Component.onCompleted: { Component.onCompleted: {
id_view.currentIndex = id_view.count
id_gp.left_menu_index_last = id_view.count
id_gp.left_menu_index_now = 0
id_view.currentIndex = 0
console.log("complete at ", id_gp.left_menu_index_now) console.log("complete at ", id_gp.left_menu_index_now)
id_timer_leftmenu.start()
} }
} }
}
Timer {
id: id_timer_leftmenu
interval: 500 // 1
repeat: true
running: true
triggeredOnStart: false
onTriggered: {
//
if (id_gp.gp_inited == 1) {
running = false;
id_gp.left_menu_index_last = id_view.count
id_gp.left_menu_index_now = 0
id_view.itemAtIndex(id_gp.left_menu_index_now).color = id_gp.left_menu_lighlight_color
} else {
pollForData();
console.log("id gp ini : " , id_gp.gp_inited )
}
}
}
function pollForData() {
//
console.log("Polling for new data...");
} }
} }

View File

@ -1,13 +1,28 @@
import QtQuick 2.15 import QtQuick 2.15
import ESP32_upper
Item { Item {
property int gp_inited: 0
property string global_banner: "Hello World" property string global_banner: "Hello World"
property int left_menu_index_now: 0 property int left_menu_index_now: 0
property int left_menu_index_last: 0 property int left_menu_index_last: 255
property string left_menu_lighlight_color: "#FF00FF" property color left_menu_lighlight_color: "#FF00FF"
property string left_menu_non_lighlight_color: "#00FF00" property color left_menu_non_lighlight_color: "#00FF00"
property string left_menu_focus_color: "#FAFA00" property color left_menu_focus_color: "#FAFA00"
property string left_menu_icon_color: "#0d4e8b" property color left_menu_icon_color: "#0d4e8b"
property int font_info_pixel_size: 20 property int font_info_pixel_size: 20
//
property color btn_normalBackground: "#FFFFFF" //
// hover
property color btn_hoverBackground: "#F0F0F0" //
// pressed
property color btn_pressedBackground: "#D0D0D0" //
// pressed
property color btn_borderColor: "#000000" //
Component.onCompleted: {
console.log("global property has been initialized");
gp_inited = 1;
}
} }

View File

@ -3,7 +3,7 @@ import QtQuick.Layouts
import ESP32_upper 1.0 import ESP32_upper 1.0
Item { Item {
anchors.fill: parent // anchors.fill: parent
ColumnLayout { ColumnLayout {
width: parent.width width: parent.width
height: parent.height height: parent.height

View File

@ -6,6 +6,10 @@ import ESP32_upper 1.0
Item { Item {
id: root id: root
GlobalProperties {
id: id_gp
}
RowLayout { RowLayout {
spacing: 0 spacing: 0