有效适用于Flickable
(即Flickable
Grid
和Rectangle
s(见下面的代码))。
以下是GridView的一个示例:
import QtQuick 2.7
import QtQuick.Controls 1.4
ApplicationWindow {
id: rootWindow
visible: true
width: 300
height: 300
Rectangle {
anchors.fill: parent
color: "yellow"
GridView {
id: gridView
anchors.fill: parent
cellWidth: 50
cellHeight: 50
model: 54
bottomMargin: 10
topMargin: 10
leftMargin: 10 // this doesn't work
rightMargin: 10 // this doesn't work
delegate: Rectangle {
width: gridView.cellWidth - 1
height: gridView.cellHeight - 1
color: "green"
}
}
}
}
答案 0 :(得分:2)
也许这就是你要找的东西:
...
GridView {
id: gridView
anchors {
fill: parent
margins: 10
}
clip: true
cellWidth: 50
cellHeight: 50
model: 54
delegate: Rectangle {
width: gridView.cellWidth - 1
height: gridView.cellHeight - 1
color: "green"
}
}
...