关于qml中listview做左右滑动界面的问题。
我想做一个用qml里的listview控件做滑动屏幕。但是我的程序在应用里没有办法显示出来。我想要的效果是每个页面三个button横排排列。代码如下
Item {
id: home
width: G.screenWidth
height: G.screenHeight
signal closed;
property int testi:0;
property bool stoptimer:false
function open() {
buttons.opacity = 1;
}
function close() {
buttons.opacity = 0;
home.closed();
}
ListView{
anchors.fill: parent
clip:true
visible:true
onMovingChanged:{
if(!moving){
if(atXBeginning) {
currentIndex = 0
} else {
currentIndex = 1
}
}
}
onCurrentIndexChanged: {
currentIndex === 0 ? positionViewAtBeginning():positionViewAtEnd()
}
delegate:Component{
Item {
// width:800
// height:480
Loader{
active: index === 0
sourceComponent: page1
}
Loader{
active: index=== 1
sourceComponent: page2
}
}
}
}
Component{
id:page1
Row{
id:homebuttons1
spacing:5
// anchors.left: parent.left
// anchors.leftMargin: 20
// anchors.top: parent.top
// anchors.topMargin: 50
// anchors.fill: parent
Repeater{
model: [
{
normalsource:"qrc:/image/home/btn_sound.png",
buttonName :qsTr("Radio"),
url:"qrc:/qml/Radio.qml",
state:true
},
{
normalsource:"qrc:/image/home/btn_sound.png",
buttonName:qsTr("Phone"),
url:"qrc:/qml/Bluetooth.qml",
state:true,
},
{
normalsource:"qrc:/image/home/btn_sound.png",
buttonName:qsTr("Phone"),
url:"qrc:/qml/Bluetooth.qml",
state:true
}
]
}
}
}
Component{
id:page2
Row{
id:homebuttons2
spacing:5
// anchors.leftMargin: 20
// anchors.top: parent.top
//anchors.topMargin: 50
// anchors.fill: parent
Repeater{
model:[
{
normalsource:"qrc:/image/home/btn_sound.png",
buttonName:qsTr("Phone"),
url:"qrc:/qml/Bluetooth.qml",
state:true
},
{
normalsource:"qrc:/image/home/btn_sound.png",
buttonName:qsTr("Phone"),
url:"qrc:/qml/Bluetooth.qml",
state:true
},
{
normalsource:"qrc:/image/home/btn_sound.png",
buttonName:qsTr("Phone"),
url:"qrc:/qml/Bluetooth.qml",
state:true
}
]
}
}
}