fix🐛: 修复显示的问题,更新button的功能
This commit is contained in:
parent
e4b0551e59
commit
a6fa2fa5d3
3
Main.qml
3
Main.qml
@ -10,9 +10,6 @@ Window {
|
||||
minimumHeight: 600
|
||||
minimumWidth: 800
|
||||
// color: "green"
|
||||
GlobalProperties {
|
||||
id: id_gp
|
||||
}
|
||||
|
||||
MainPage {
|
||||
id: id_home_page
|
||||
|
||||
@ -33,15 +33,30 @@ Item {
|
||||
}
|
||||
|
||||
Button {
|
||||
Layout.preferredWidth: 100
|
||||
id: button
|
||||
text: "重新连接"
|
||||
hoverEnabled: false
|
||||
Layout.preferredWidth: 100
|
||||
Layout.preferredHeight: 50
|
||||
font.pixelSize: id_gp.font_info_pixel_size
|
||||
background: Rectangle { // 自定义背景
|
||||
color: control.pressed ? "lightblue" : "blue"
|
||||
border.color: "black"
|
||||
|
||||
background: Rectangle {
|
||||
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
|
||||
}
|
||||
|
||||
// 使 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: {
|
||||
console.log("press butn")
|
||||
}
|
||||
|
||||
@ -20,14 +20,15 @@ Item {
|
||||
source: "qrc:/assets/img/terminal-box-fill.svg"
|
||||
smooth: true // 使图片平滑缩放
|
||||
asynchronous: true // 异步加载图片
|
||||
}
|
||||
|
||||
// 使用 ColorOverlay 修改 SVG 颜色
|
||||
ColorOverlay {
|
||||
anchors.fill: id_svg_icon_info_lb
|
||||
source: id_svg_icon_info_lb
|
||||
anchors.fill: parent
|
||||
source: parent
|
||||
color: id_gp.left_menu_non_lighlight_color // 修改后的 SVG 图片颜色
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Text {
|
||||
text: "芯片类型:"
|
||||
|
||||
@ -8,11 +8,8 @@ Item {
|
||||
|
||||
Component {
|
||||
id: contactDelegate
|
||||
// property int my_index: index
|
||||
Rectangle {
|
||||
width: 60; height: 60
|
||||
anchors.left: parent.left // 靠父组件左边
|
||||
anchors.leftMargin: 10 // 左边距20像素
|
||||
radius: 5
|
||||
color: id_gp.left_menu_non_lighlight_color
|
||||
MouseArea {
|
||||
@ -100,6 +97,7 @@ Item {
|
||||
id: id_view
|
||||
spacing: 10
|
||||
topMargin: 10
|
||||
leftMargin: 10
|
||||
anchors.fill: parent
|
||||
model: TestModels {}
|
||||
delegate: contactDelegate
|
||||
@ -108,18 +106,42 @@ Item {
|
||||
snapMode: ListView.SnapToItem
|
||||
onCurrentIndexChanged: {
|
||||
// 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_now).color = id_gp.left_menu_lighlight_color
|
||||
}
|
||||
|
||||
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)
|
||||
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...");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,13 +1,28 @@
|
||||
import QtQuick 2.15
|
||||
import ESP32_upper
|
||||
|
||||
Item {
|
||||
property int gp_inited: 0
|
||||
property string global_banner: "Hello World"
|
||||
property int left_menu_index_now: 0
|
||||
property int left_menu_index_last: 0
|
||||
property string left_menu_lighlight_color: "#FF00FF"
|
||||
property string left_menu_non_lighlight_color: "#00FF00"
|
||||
property string left_menu_focus_color: "#FAFA00"
|
||||
property string left_menu_icon_color: "#0d4e8b"
|
||||
property int left_menu_index_last: 255
|
||||
property color left_menu_lighlight_color: "#FF00FF"
|
||||
property color left_menu_non_lighlight_color: "#00FF00"
|
||||
property color left_menu_focus_color: "#FAFA00"
|
||||
property color left_menu_icon_color: "#0d4e8b"
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ import QtQuick.Layouts
|
||||
import ESP32_upper 1.0
|
||||
|
||||
Item {
|
||||
anchors.fill: parent
|
||||
// anchors.fill: parent
|
||||
ColumnLayout {
|
||||
width: parent.width
|
||||
height: parent.height
|
||||
|
||||
@ -6,6 +6,10 @@ import ESP32_upper 1.0
|
||||
Item {
|
||||
id: root
|
||||
|
||||
GlobalProperties {
|
||||
id: id_gp
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
spacing: 0
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user