首页| 论坛| 消息

标题:ListView切换页面问题
作者:sikylori
日期:2016-03-26 23:42
内容:

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 {
&nbs ..


#1 [马侬骑士 03-27 11:13]
修改为: onPressAndHold: listView.positionViewAtIndex(listView.currentIndex,ListView.Beginning )
就可以正常运行了
不过,原来怎么问题我也清楚
#2 回 马侬骑士 的帖子 [sikylori 03-28 08:36]
马侬骑士:修改为: onPressAndHold: listView.positionViewAtIndex(listView.currentIndex,ListView.Beginning )
就可以正常运行了
不过,原来怎么问题我也清楚 (2016-03-27 11:13) 
谢谢,使用这种方法是可以切换页面,但没有了incrementCurrentIndex()时那种页面切换动画了

回复 发表
主题 版块