下面的代码工作正常(多亏了西尔万),只有当ListView的顶部行覆盖buttonRow时,它才能正常工作。知道吗?-
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
}
}
}
}
}
发布于 2014-04-12 22:05:29
可闪烁项将其子项放置在可被拖动和弹出的表面上,从而使视图滚动到子项上。此行为构成了设计用于显示大量子项(如ListView和GridView )的项的基础。
在传统用户界面中,可以使用标准控件(如滚动条和箭头按钮)滚动视图。在某些情况下,也可以通过在移动光标时按下并按住鼠标按钮直接拖动视图。在基于触摸的用户界面中,此拖动操作通常由一个闪烁操作补充,其中滚动在用户停止触摸视图后继续进行。
Flickable不会自动剪辑其内容。如果未将其用作全屏项,则应考虑将剪辑属性设置为true
。
因此,示例代码现在如下所示:
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
}
}
}
}
}
https://askubuntu.com/questions/446997
复制相似问题