首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在QML中的列中滚动ListView

在QML中的列中滚动ListView
EN

Ask Ubuntu用户
提问于 2014-04-12 21:01:45
回答 1查看 10.8K关注 0票数 3

下面的代码工作正常(多亏了西尔万),只有当ListView的顶部行覆盖buttonRow时,它才能正常工作。知道吗?-

代码语言:javascript
运行
复制
import QtQuick 2.0
import Ubuntu.Components 0.1

MainView {
width: units.gu(60)
height: units.gu(60)

ListModel {
    id: fruitModel
    ListElement {
        name: "Apple"
        cost: 2.45
    }
    ListElement {
        name: "Orange"
        cost: 3.25
    }
    ListElement {
        name: "Banana"
        cost: 1.95
    }
}

Page {
    id: test

    Column {
        spacing: units.gu(1)
        id: pageLayout
        anchors {
            margins: units.gu(2)
            fill: parent
        }

        Row {
            id: buttonRow
            spacing: units.gu(1)
            Button {
                objectName: "button1"
                color: "white"
                text: i18n.tr("Help")
            }
            Button {
                objectName: "button2"
                color: "black"
                text: i18n.tr("Search")
            }
        }

        Item {
            anchors.top: buttonRow.bottom
            ListView {
                id: list
                width: units.gu(18)
                height: units.gu(3)
                model: fruitModel
                boundsBehavior: Flickable.StopAtBounds
                delegate: Row {
                    Text { text: "Fruit: " + name }
                    Text { text: "Cost: $" + cost }
                }
            }
            Scrollbar {
                flickableItem: list
                align: Qt.AlignTrailing
            }
        }
    }
}
}
EN

回答 1

Ask Ubuntu用户

回答已采纳

发布于 2014-04-12 22:05:29

可闪烁项将其子项放置在可被拖动和弹出的表面上,从而使视图滚动到子项上。此行为构成了设计用于显示大量子项(如ListView和GridView )的项的基础。

在传统用户界面中,可以使用标准控件(如滚动条和箭头按钮)滚动视图。在某些情况下,也可以通过在移动光标时按下并按住鼠标按钮直接拖动视图。在基于触摸的用户界面中,此拖动操作通常由一个闪烁操作补充,其中滚动在用户停止触摸视图后继续进行。

Flickable不会自动剪辑其内容。如果未将其用作全屏项,则应考虑将剪辑属性设置为true

因此,示例代码现在如下所示:

代码语言:javascript
运行
复制
import QtQuick 2.0
import Ubuntu.Components 0.1

MainView {
    width: units.gu(60)
    height: units.gu(60)

    ListModel {
        id: fruitModel
        ListElement {
            name: "Apple"
            cost: 2.45
        }
        ListElement {
            name: "Orange"
            cost: 3.25
        }
        ListElement {
            name: "Banana"
            cost: 1.95
        }
    }

    Page {
        id: test

        Column {
            spacing: units.gu(1)
            id: pageLayout
            anchors {
                margins: units.gu(2)
                fill: parent
            }

            Row {
                id: buttonRow
                spacing: units.gu(1)
                Button {
                    objectName: "button1"
                    color: "white"
                    text: i18n.tr("Help")
                }
                Button {
                    objectName: "button2"
                    color: "black"
                    text: i18n.tr("Search")
                }
            }

            Item {
                anchors.top: buttonRow.bottom
                ListView {
                    id: list
                    clip: true
                    width: units.gu(18)
                    height: units.gu(3)
                    model: fruitModel
                    boundsBehavior: Flickable.StopAtBounds
                    delegate: Row {
                        Text { text: "Fruit: " + name }
                        Text { text: "Cost: $" + cost }
                    }
                }
                Scrollbar {
                    flickableItem: list
                    align: Qt.AlignTrailing
                }
            }
        }
    }
}
票数 2
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/446997

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档