我需要使用网格(不是 gridview),并且我需要实现 GridView.SnapToRow 。
下面是我的代码:
import QtQuick 1.0
Rectangle {
width: 1368
height: 768
Text{
id:parentTxt
anchors.top: parentTxt0.bottom
}
Timer{running: true;repeat: false;interval:200;onTriggered: {calc()}}
function calc(){
var totalItems=testGrid.count+((testBtn.visible)?1:0)
var dividedVal=totalItems/testGrid.columns
var absVal=Math.floor(dividedVal)
var diffVal=dividedVal-absVal;
testGrid.rowCount=(diffVal>0)?(absVal+1):absVal
parentTxt.text=testGrid.rowCount
}
Text{
id:parentTxt0
text:"Move up"
MouseArea{
anchors.fill: parent;
onClicked: {
calc()
gridFlick.contentY+=137
}
}
}
Text{
id:parentTxt02
text:"Move down"
anchors.left: parentTxt0.right
anchors.leftMargin: 20
MouseArea{
anchors.fill: parent;
onClicked: {
calc()
if(gridFlick.contentY!=0)gridFlick.contentY-=137
}
}
}
Text{
id:parentTxt03
text:"toggleVisiblitiy"
anchors.left: parentTxt02.right
anchors.leftMargin: 20
MouseArea{
anchors.fill: parent;
onClicked: {
testBtn.visible=!testBtn.visible;
calc()
}
}
}
Rectangle {
width: 770
height: 274
anchors.centerIn: parent
color:"#330000ff"
clip:true;
Flickable{
id:gridFlick
interactive: true;
width: parent.width
height: parent.height
contentWidth: testGrid.width; contentHeight: 137*testGrid.rowCount
flickableDirection:Flickable.VerticalFlick
boundsBehavior:Flickable.StopAtBounds
Grid{
id:testGrid
property int count:15
property int rowCount: 0
columns: 5;
width: parent.width
height: parent.height
Rectangle{
id:testBtn
color:"transparent"
height:137
width: 154
Text {
anchors.centerIn: parent;
wrapMode: Text.WordWrap
text: "back"
}
MouseArea{
anchors.fill: parent;
onClicked: {
parentTxt.text="back"
}
}
}
Repeater{
model:testGrid.count;
delegate:Rectangle{
color:"transparent"
height:137
width: 154
Text {
anchors.centerIn: parent;
wrapMode: Text.WordWrap
text: index
}
MouseArea{
anchors.fill: parent;
onClicked: {
parentTxt.text=index
}
}
}
}
}
}
}
}
任何人都可以对此提供一些想法吗?