我在 Flickable 中有一个 backGroundList 和顶部 gridview。
我想要处理 gridview contentY ,来自父 Flickable 的 Y 位置,当我将 gridview 高度指定为内容高度时它正在工作,但由于内存问题,我不想在之前创建项目。
代码:
Flickable {
id: mainFlickable
width: 1920
height: 1080
contentHeight: gridView.contentHeight + 660 + 140 // topmargin + bottom margin
ListView {
id:backGroundList
width: 1920
height: 1080
y: mainFlickable.contentY
orientation: ListView.Horizontal
MouseArea {
id: myMA12
anchors.fill: parent
hoverEnabled: true
}
}
GridView {
id: gridView
objectName: "gridView"
width: 1920
height: 1080
cellWidth: 372
cellHeight: 290
interactive: false
y: {
if (mainFlickable.contentY > 660)
return 660 + (mainFlickable.contentY - 660)
else
return 660
}
contentY: {
if (mainFlickable.contentY > 660){
return (mainFlickable.contentY - 660)
}
else {
return 0
}
}
delegate: Rectangle {
width: 352
height: 270
color: "blue"
opacity: 0.5
Text {
text: index
anchors.centerIn: parent
}
}
model:100
anchors {
left: parent.left
leftMargin: 30
right: parent.right
rightMargin: 30
}
}
}
它没有按预期工作。当我更新 Y 值时 ContentY 自动更新为零
约束:Qt5.9.0
有人可以帮助我吗?
如果我理解正确的话,您希望将两个...View
放在另一个之上。当其中一个弹到最后时,您希望将其View
从窗口中弹出,第二个出现并开始轻弹。
在我看来,这不是完全可以通过Flickable
嵌套其他两个来实现的。
通过使用Flickable
与它们同级的a 很容易实现。在我的示例代码中,我使用了两个 Flickable。一个用于控制contentY
- 属性,另一个负责在两个View
s 之间滚动。后者可以通过使用Item
替代来轻松、更有效地解决。
Window {
id: rootWin
width: 800; height: 600; visible: true
Flickable {
id: flck
anchors.fill: parent
contentHeight: lv1.height + lv2.height
interactive: false
contentY: Math.min(Math.max(0, mainFlick.contentY - lv1.contentHeight + lv1.height), contentHeight - height)
ListView {
id: lv1
height: rootWin.height
width: 100
model: 90
delegate: Rectangle {
border.width: 1
width: 100
height: 50
Text {
anchors.centerIn: parent
text: index
}
}
interactive: false
contentY: Math.min(mainFlick.contentY, contentHeight - height)
onContentYChanged: console.log(contentY, contentHeight, height)
}
ListView {
id: lv2
height: rootWin.height
anchors.top: lv1.bottom
width: 100
model: 90
delegate: Rectangle {
border.width: 1
width: 100
height: 50
Text {
anchors.centerIn: parent
text: index
}
}
interactive: false
contentY: Math.min(Math.max(0, mainFlick.contentY - lv1.contentHeight), contentHeight - height)
}
}
Flickable {
id: mainFlick
anchors.fill: parent
contentHeight: lv1.contentHeight + lv2.contentHeight
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句