今天下午想试一下用QML实现轮播图,用的是SwipeView和PageIndicator,在实现过程中,我发现会一次性出现2张图片,后来发现只是因为SwipeView这个组件并不是真正一次显示一个组件,所以解决办法就是在给它一个Rectangle作为父组件,并且clip设为true以截断多出来的部分,代码如下。
import QtQuick 2.0
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.14
Rectangle {
id:userwindow;
//图片地址数组↓
property var imagelist: ["https://tu1.whhost.net/uploads/20181011/23/1539271568-CDgeBNfqrn.jpg"
,"http://pic.haixia51.com/pic/?p=/qianqianhua/20180518/03/1526585503-fisYUGPeyv.jpg"
,"http://img.juimg.com/tuku/yulantu/110111/292-110111035J3100.jpg"];
property var i: 0;
//图片组件
Component{
id:swipeImage;
Image{
asynchronous: true;
}
}
Rectangle{
id:rect;
width: parent.width/2;
height: parent.height/2;
anchors.top: parent.top;
anchors.topMargin: 20;
anchors.horizon