查看完整版本: [-- ListView切换页面问题 --]

QTCN开发网 -> Qt QML开发 -> ListView切换页面问题 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

sikylori 2016-03-26 23:42

ListView切换页面问题

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();
            }
        }
    }
}


马侬骑士 2016-03-27 11:13
修改为: onPressAndHold: listView.positionViewAtIndex(listView.currentIndex,ListView.Beginning )
就可以正常运行了

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

sikylori 2016-03-28 08:36
马侬骑士:修改为: onPressAndHold: listView.positionViewAtIndex(listView.currentIndex,ListView.Beginning )
就可以正常运行了
不过,原来怎么问题我也清楚 (2016-03-27 11:13) 

谢谢,使用这种方法是可以切换页面,但没有了incrementCurrentIndex()时那种页面切换动画了


查看完整版本: [-- ListView切换页面问题 --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled