Qt版本:Qt5.5.1
功能描述: 本人使用QML中的ListView控件实现像手机上的桌面左右拖拽切换的功能
问题描述: 点击listDelegate中Rectangle调用listView.incrementCurrentIndex();进行下一页操作,这里没问题;然后长按listDelegate中Rectangle同样调用listView.incrementCurrentIndex();进行下一页操作,这里就出现问题了,页面没有切换过去,但onCurrentIndexChanged函数里打印出currentIndex已变为下一个index了,请问有什么方法可提供解决,这个问题在QtQuick 1.0上是没有的,2.0后才出现,不知道是不是有什么新属性没设好
本人也试了将"highlightRangeMode: ListView.StrictlyEnforceRange;"这句话去掉,然后长按操作,页面是可以切换过去了,但直接用鼠标左右滑动来切页面时,currentIndex 值又不跟着页面切换而改变,求指导
代码如下:
import QtQuick 2.5
import QtQuick.Window 2.2
Window {
width: 1024;
height: 600;
visible: true
ListView {
id: listView;
anchors.fill: parent
model: 3
delegate: listDelegate
orientation: ListView.Horizontal;
snapMode: ListView.SnapOneItem;
highlightRangeMode: ListView.StrictlyEnforceRange;
onCurrentIndexChanged: console.log("onCurrentIndexChanged(): " + listView.currentIndex);
}
Component {
id: listDelegate
Rectangle {
width: 1024; height: 600
color: (index%2 == 0) ? "#FF0000" : "#00FF00";
MouseArea {
anchors.fill: parent;
onClicked: listView.incrementCurrentIndex();
onPressAndHold: listView.incrementCurrentIndex();
}
}
}
}