【QT】QT的学习:qml中使用listmode、listview实现选项的变换操作,类似qwidget中listwidget的作用。

(1)方法一:点击某一选项,某一个选项的颜色就立即会发生变化

ListView {
id : m_listView
anchors.fill: parent
anchors.margins: 20
clip: true
model: ["A","B","C","D","E"]
delegate: m_listDelegate
spacing: 5
focus: true
}

Component {
id: m_listDelegate

Rectangle {
width: ListView.view.width
height: 40
color: ListView.isCurrentItem?"#157efb":"#53d769" //选中颜色设置
border.color: Qt.lighter(color, 1.1)
Text {
anchors.centerIn: parent
font.pixelSize: 10
text: modelData + index
}

MouseArea {
anchors.fill: parent
onClicked: m_listView.currentIndex = index  //实现item切换
}
}
}

(2)方法二:点击某一选项,某一个选项的颜色就会从别的选项移动过来,移动的比较慢就跟动画一样。

ListView {
id : m_listView
anchors.fill: parent
anchors.margins: 20
clip: true
model: ["A","B","C","D","E"]
delegate: m_listDelegate

highlight: Rectangle{
        color: "lightblue"//高亮条
    }
 highlightFollowsCurrentItem: true//高亮条随着item的变化而移动
spacing: 5
focus: true
}

Component {
id: m_listDelegate

Rectangle {
width: ListView.view.width
height: 40
border.color: Qt.lighter(color, 1.1)
Text {
anchors.centerIn: parent
font.pixelSize: 10
text: modelData + index
}

MouseArea {
anchors.fill: parent
onClicked: m_listView.currentIndex = index  //实现item切换
}
}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值