fix🐛: 修复显示的问题,更新button的功能
This commit is contained in:
parent
e4b0551e59
commit
a6fa2fa5d3
3
Main.qml
3
Main.qml
@ -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
|
||||||
|
|||||||
@ -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")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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: "芯片类型:"
|
||||||
|
|||||||
@ -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...");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user