2023年6月20日发(作者:)
QMLListView添加滚动条ListView添加滚动条,利⽤ntal: ScrollBar { id: hbar; active: }; al: ScrollBar { id: vbar;active: }的⽅式有问题(⽔平⽅向的⽐较严重)。所以采⽤另外⼀种⽅式。代码如下import QtQuick 2.9import ls 2.3/*****************************************************// 此⽂件主要实现1. listview添加滚动条,⽔平⽅向和竖直⽅向。2.实现选中的效果// 实现函数:动态添加数据,清除全部数据。*****************************************************/Rectangle{ id : mrect color: "#ff0000" width: 200; height: 200 clip: true property int listviewwidth: 400 property int listviewheigth: 400 function addElement(ele) { (ele) } function clearData() { (); } //测试动态添加数据 leted: { for (var i = 0 ; i< 10;++i) addElement({"name":"测试完成","mcolor":"#dd0000","number":i+1}) } / ListModel { id : dmode } ListView { ListView { id : listview; width: listviewwidth; height: listviewheigth y : -on*height x : -on*width model: dmode delegate: Rectangle { color: entItem ? "black" : "green" //实现选择效果 : "white" height : 30; width : : 0 Text { lineHeightMode : eight lineHeight : 30 horizontalAlignment : Center verticalAlignment : Center text: name + number color: mcolor } MouseArea { : parent onClicked: tIndex = index //实现item切换 实现选择效果 } } } ScrollBar { id: vbar hoverEnabled: true active: hovered || pressed orientation: al size: / : : : policy: On //定义样式// contentItem: Rectangle {// implicitWidth: 6// implicitHeight: 100// radius: width / 2// color: d ? "#81e889" : "#c2f4c6"// } } ScrollBar { id: hbar hoverEnabled: true active: hovered || pressed orientation: ntal size: / : : : //policy: On //policy: On //定义样式// contentItem: Rectangle {// //implicitWidth: 6// //implicitHeight: 100// radius: width / 2// color: d ? "#81e889" : "#c2f4c6"// } }}
2023年6月20日发(作者:)
QMLListView添加滚动条ListView添加滚动条,利⽤ntal: ScrollBar { id: hbar; active: }; al: ScrollBar { id: vbar;active: }的⽅式有问题(⽔平⽅向的⽐较严重)。所以采⽤另外⼀种⽅式。代码如下import QtQuick 2.9import ls 2.3/*****************************************************// 此⽂件主要实现1. listview添加滚动条,⽔平⽅向和竖直⽅向。2.实现选中的效果// 实现函数:动态添加数据,清除全部数据。*****************************************************/Rectangle{ id : mrect color: "#ff0000" width: 200; height: 200 clip: true property int listviewwidth: 400 property int listviewheigth: 400 function addElement(ele) { (ele) } function clearData() { (); } //测试动态添加数据 leted: { for (var i = 0 ; i< 10;++i) addElement({"name":"测试完成","mcolor":"#dd0000","number":i+1}) } / ListModel { id : dmode } ListView { ListView { id : listview; width: listviewwidth; height: listviewheigth y : -on*height x : -on*width model: dmode delegate: Rectangle { color: entItem ? "black" : "green" //实现选择效果 : "white" height : 30; width : : 0 Text { lineHeightMode : eight lineHeight : 30 horizontalAlignment : Center verticalAlignment : Center text: name + number color: mcolor } MouseArea { : parent onClicked: tIndex = index //实现item切换 实现选择效果 } } } ScrollBar { id: vbar hoverEnabled: true active: hovered || pressed orientation: al size: / : : : policy: On //定义样式// contentItem: Rectangle {// implicitWidth: 6// implicitHeight: 100// radius: width / 2// color: d ? "#81e889" : "#c2f4c6"// } } ScrollBar { id: hbar hoverEnabled: true active: hovered || pressed orientation: ntal size: / : : : //policy: On //policy: On //定义样式// contentItem: Rectangle {// //implicitWidth: 6// //implicitHeight: 100// radius: width / 2// color: d ? "#81e889" : "#c2f4c6"// } }}
发布评论