简体   繁体   English

QML flickable无法正常工作

[英]QML flickable not working

I'm trying to learn QML so that I'll be able to create a smartphone app. 我正在尝试学习QML,以便我能够创建智能手机应用程序。 Right now I'm trying to create a list where each item should be "flickable" , this is what I want: When you grab a list item you should be able to drag it to the left (to reveal a menu below) and the actual list item should not completely disappear to the left edge, but still be a bit visible so you can drag it back. 现在我正在尝试创建一个列表,其中每个项目应该是“可以轻弹” ,这就是我想要的:当你抓住一个列表项时,你应该能够将它拖到左边(以显示下面的菜单)和实际列表项应该完全消失的左边缘,但还是有点可见这样你就可以将其拖回。 A solution as simple as possible would be appreciated :)! 一个尽可能简单的解决方案将不胜感激:)!

Here's my start at it (only making the last rectangle flickable): 这是我的开始(仅使最后一个矩形可以闪烁):

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
            }
        }
    }

}

I figured it out! 我想到了! You just have to set the contentWidth to larger than the width of the Flickable . 您只需将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
            }
        }

I like to set the contentWidth and contentHeight depending on the size of the Children. 我喜欢根据Children的大小设置contentWidth和contentHeight。 The only important thing is you have to bind to the size of contentItem.childrenRect. 唯一重要的是你必须绑定到contentItem.childrenRect的大小。 This took me almost a day to realize, maybe it will help you. 这花了我差不多一天才意识到,也许它会对你有所帮助。

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
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM