关于qml中listview做左右滑动界面的问题。

ssfcool 2017-04-13 04:43:25

我想做一个用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
}

]
}
}
}
...全文
772 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

16,216

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧