我在QML中遇到了GridView的问题,我创建了一个月的日历,GridView的每个单元格都是一天,并且在当天为每个事件放置一个项目时,我尝试在单元格,但当我尝试向右移动时,隐藏在GridView的单元格中,当我将项目移动到左边的单元格时,这不会发生,附加完整的代码,以防我有alguan想法修复,问候
Main.qml
import QtQuick 2.2
import QtQuick.Window 2.1
Window {
visible: true
width: 360
height: 360
GridView
{
id: grid
x:0
y:0
interactive: false//para que no se mueva la rejilla
highlightFollowsCurrentItem: false
highlightRangeMode:GridView.StrictlyEnforceRange
anchors.bottom: parent.bottom
width: parent.width
cellWidth: parent.width / 7
cellHeight: parent.height / 6
anchors.top://parte para inculir la fila del nombre de las fechas
{
return parent.top
}
model: 42
delegate: MonthCellBig{}
flickableChildren: MouseArea
{
anchors.fill: parent
onClicked:
{
mouseToPosition(mouse.x, mouse.y)
}
}
}
//necesario para crear un nuevo item
function mouseToTimePosition(mouseX, mouseY)
{
//if(mouseY < 0 || mouseY > appwnd.height) return;
var columnID = Math.floor(mouseX / grid.cellWidth);
var rowID = Math.floor(mouseY / grid.cellHeight);
var offset = Math.floor(((rowID * 7) + columnID) + 1);
//var day = offset - m_monthStartAt + 1;
return {dia: offset}
}
// para conseguir el dia donde ha echo click el usuario
function mouseToPosition(mouseX, mouseY)
{
var cellData = mouseToTimePosition(mouseX, mouseY)
//console.log(cellData.dia)
}
}
MonthCellBig.qml
import QtQuick 2.0
Rectangle
{
id: parentRectangle
width: grid.cellWidth - 1
height: grid.cellHeight - 1
Rectangle
{
id: rectangleCell
color: "transparent"
anchors.fill: parent
//para la separacion entre las lineas del rectangle
anchors.leftMargin: -1
anchors.rightMargin: -1
anchors.topMargin: -1
anchors.bottomMargin: -1
Column
{
id:columnItem
//y: txtNumberDay.height + 3
spacing: 2
Repeater
{
model: 2
Rectangle
{
id: itemData
width: rectangleCell.width; height: txtItem.height; radius: 10; color: "green"
Text
{
id: txtItem
text: qsTr("text")
}
MouseArea
{
id: mouseArea
acceptedButtons: Qt.LeftButton
anchors.fill: parent
width: grid.rectWidth - 5
height: grid.rectHeight - 5
drag.target: itemData
drag.axis: Drag.XAxis
//onClicked:{ grid.End; console.log("EEE");}
}
}
}
}
}
}