• 4055阅读
  • 2回复

[提问]ListView切换页面问题 [复制链接]

上一主题 下一主题
离线sikylori
 

只看楼主 倒序阅读 楼主  发表于: 2016-03-26
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();
            }
        }
    }
}

离线马侬骑士

只看该作者 1楼 发表于: 2016-03-27
修改为: onPressAndHold: listView.positionViewAtIndex(listView.currentIndex,ListView.Beginning )
就可以正常运行了

不过,原来怎么问题我也清楚
离线sikylori

只看该作者 2楼 发表于: 2016-03-28
回 马侬骑士 的帖子
马侬骑士:修改为: onPressAndHold: listView.positionViewAtIndex(listView.currentIndex,ListView.Beginning )
就可以正常运行了
不过,原来怎么问题我也清楚 (2016-03-27 11:13) 

谢谢,使用这种方法是可以切换页面,但没有了incrementCurrentIndex()时那种页面切换动画了
快速回复
限100 字节
 
上一个 下一个