首页 文章

QML flickable无法正常工作

提问于
浏览
4

我'm trying to learn QML so that I'将能够创建智能手机应用程序 . 现在我正在尝试创建 a list where each item should be "flickable" ,这就是我想要的:当你 grab 一个列表项时,你应该可以将它拖到左边(以显示下面的菜单),实际的列表项不应该完全消失到左边缘,但仍然有点可见,所以你可以拖回来 . 一个解决方案 as simple as possible 将不胜感激:)!

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

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 回答

  • 1

    我想到了!您只需将 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
                }
            }
    
  • 4

    我喜欢根据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
        }
    }
    

相关问题