qml实现数字滚动选择器
效果图
list view 实现
model是需要显示的数据,可通过设置最小值最大值以及步长控制
核心代码
(代理可以变成图标)
delegate: Rectangle{
width: root.width
height: root.height
color: "pink"
Text {
id:numText
text: num
anchors.centerIn: parent
font.bold: true
font.pointSize: listView.currentIndex == index ? 50 : 35
color: listView.currentIndex == index ? "#00BFFF": "black"
//font.pointSize:25
}
MouseArea{
anchors.fill: parent
onClicked: {
listView.currentIndex = index
sig_NumSelected(num)
// parent.forceActiveFocus() //强制获得焦点,用于在失去焦点时候切换状态
}
}
}
使用方式
MyNumSelecter{
anchors.centerIn: parent
numWid:100 //代理 宽度
numHeight:100 //代理高度
min:30 //最小值
max: 100 //最大值
step: 10 //步长
}
资源
https://download.csdn.net/download/qq_36234113/12611354