72 lines
2.3 KiB
QML
72 lines
2.3 KiB
QML
import QtQuick 2.14
|
|
import QtQuick.Controls 2.14
|
|
import "qrc:/QmlFiles/qml/components"
|
|
|
|
Button {
|
|
id: leftToolBarButton
|
|
property string iconSource: ""
|
|
property string buttonText: "" // 新增属性,用于设置文字
|
|
property color clickedColor: Colors.sColor_BlackWithWhite
|
|
property color hoverColor: Colors.sColor_BlackWithWhite
|
|
property int buttonWidth: 40 // 默认宽度
|
|
property int buttonHeight: 40 // 默认高度
|
|
|
|
width: buttonWidth
|
|
height: buttonHeight
|
|
implicitWidth: buttonWidth
|
|
implicitHeight: buttonHeight
|
|
|
|
background: Rectangle {
|
|
width: parent.width
|
|
height: parent.height
|
|
color: "transparent"
|
|
border.color: "red"
|
|
border.width: 0
|
|
radius: 0
|
|
|
|
MouseArea {
|
|
id: mouseArea
|
|
anchors.fill: parent
|
|
hoverEnabled: true
|
|
|
|
onEntered: {
|
|
parent.color = leftToolBarButton.hoverColor
|
|
}
|
|
|
|
onExited: {
|
|
parent.color = "transparent"
|
|
}
|
|
onClicked: {
|
|
leftToolBarButton.clicked()
|
|
}
|
|
}
|
|
}
|
|
|
|
contentItem: Row { // 使用 Row 布局容器
|
|
id: contentRow
|
|
anchors.fill: parent
|
|
anchors.left: parent.left // 靠左对齐
|
|
anchors.verticalCenter: parent.verticalCenter // 垂直居中
|
|
spacing: 18 // 图片和文字之间的间距
|
|
|
|
Image {
|
|
id: image
|
|
source: leftToolBarButton.iconSource
|
|
width: leftToolBarButton.buttonHeight // 使用 buttonHeight 作为宽度,保持图标为正方形
|
|
height: leftToolBarButton.buttonHeight
|
|
fillMode: Image.PreserveAspectFit
|
|
}
|
|
|
|
// Text {
|
|
// id: textLabel
|
|
// text: leftToolBarButton.buttonText // 使用新增的 buttonText 属性
|
|
// font.pixelSize: 32 // 设置字体大小
|
|
// font.family: "Microsoft YaHei" // 设置字体为微软雅黑
|
|
// font.bold: true // 设置加粗
|
|
// verticalAlignment: Text.AlignVCenter
|
|
// height: leftToolBarButton.buttonHeight // 高度固定为 40 像素
|
|
// color: "white" // 设置文字颜色为白色
|
|
// font.letterSpacing: 5 // 设置文字间距为 10 像素
|
|
// }
|
|
}
|
|
} |