QML flickable无法正常工作

时间:2014-02-19 13:24:38

标签: qt user-interface qml qt-quick

我正在尝试学习QML,以便我能够创建智能手机应用程序。现在我正在尝试创建列表,其中每个项目应该是“可以轻弹”,这就是我想要的:当你抓住一个列表项时,你应该能够将它拖到左边(到显示下面的菜单)并且实际的列表项应该完全消失到左边缘,但仍然有点可见,所以你可以将它拖回来。一个解决方案尽可能简单将不胜感激:)!

这是我的开始(仅使最后一个矩形可以轻弹):

import QtQuick 2.0

Rectangle {
    width: 360
    height: 360

    Column {
        spacing: 5
        Rectangle {
            color: "green"
            width: 360
            height: 360/3
        }

        Rectangle {
            color: "red"
            width: 360
            height: 360/3
        }

        Flickable{
            interactive: true
            boundsBehavior: Flickable.StopAtBounds
            contentHeight: flickme.height
            contentWidth: flickme.width
            width: 360
            height: 360/3
            Rectangle {
                id:flickme
                color: "yellow"
                width: 360
                height: 360/3
            }
        }
    }

}

2 个答案:

答案 0 :(得分:4)

我明白了!您只需将contentWidth设置为大于Flickable的宽度。

Flickable{
            interactive: true
            boundsBehavior: Flickable.StopAtBounds
            contentHeight: flickme.height
            contentWidth: flickme.width*1.8
            width: 360
            height: 360/3
            Rectangle {
                id:flickme
                color: "yellow"
                width: 360
                height: 360/3
            }
        }

答案 1 :(得分:1)

我喜欢根据Children的大小设置contentWidth和contentHeight。唯一重要的是你必须绑定到contentItem.childrenRect的大小。这花了我差不多一天才意识到,也许它会对你有所帮助。

Flickable {
    interactive: true
    boundsBehavior: Flickable.StopAtBounds
    contentHeight: contentItem.childrenRect.height
    contentWidth: contentItem.childrenRect.width
    width: 360
    height: 360/3
    Rectangle {
        id:flickme
        color: "yellow"
        width: 360
        height: 360/3
    }
}
相关问题