import QtQuick 2.0
import QtQuick.Controls 2.12
Switch{
id:control
property color backgroundColor: control.checked? "#3d73ff" : "#9FB7CE"
property alias ischeck: control.checked
signal checkChange(bool check)
onClicked: {
control.checkChange(ischeck);
}
indicator: Rectangle{
implicitWidth: 40
implicitHeight:24
x:control.leftPadding
y:parent.height / 2 - height / 2;
radius: 12
color: control.backgroundColor
border.color: control.backgroundColor
//小圆点
Rectangle{
id:smallRect
width: 18
height: 18
radius: 13
color: "#FFFFFF"
border.color: "#999999"
anchors.verticalCenter: parent.verticalCenter
//改变小圆点位置
NumberAnimation on x{
to:smallRect.width
running: control.checked? true : false;
duration: 0
}
NumberAnimation on x{
to:0
running: control.checked? false : true;
duration: 0
}
}
}
//要显示的文本
// contentItem: Text {
// text: qsTr("text")
// color: "#4e5969"
// verticalAlignment: Text.AlignVCenter
// anchors.right: indicator.left
// font{
// family: "Microsoft YaHei"
// pixelSize: 14
// }
// }
}
QML选择按钮封装
最新推荐文章于 2025-03-17 08:00:00 发布