Qt 如何在QML的Listview中保留特定列表项之间的空间
我有一个包含一些列表项的列表视图。但是我需要在列表视图中的第二个和第三个列表项之间留一个空格 我已尝试在列表视图组件.oncompleted()中设置特定项的高度。在列表视图中,若我滚动到最后一个项目,并且向上移动component.oncompleted中设置的height属性并没有任何效果,那个么那个时我可以有大约30个项目。是否有其他方法保留第二个和第三个列表项之间的空格Qt 如何在QML的Listview中保留特定列表项之间的空间,qt,listview,qml,Qt,Listview,Qml,我有一个包含一些列表项的列表视图。但是我需要在列表视图中的第二个和第三个列表项之间留一个空格 我已尝试在列表视图组件.oncompleted()中设置特定项的高度。在列表视图中,若我滚动到最后一个项目,并且向上移动component.oncompleted中设置的height属性并没有任何效果,那个么那个时我可以有大约30个项目。是否有其他方法保留第二个和第三个列表项之间的空格 import QtQuick 2.9 import QtQuick.Window 2.2 Window {
import QtQuick 2.9
import QtQuick.Window 2.2
Window
{
visible: true
width: 1920
height: 1080
color: "black"
property var curritem
property var items
ListView
{
id:idlistview
model:SampleListModel{}
x:350
y:200
width: 700
height: 500
clip: true
spacing: 10
focus: true
highlight: Rectangle
{
x: 85
y: idlistview.currentItem.y
width: 400
height: 66
color: "grey"
Behavior on y
{
SpringAnimation{spring: 2;damping: 0.1}
}
}
highlightFollowsCurrentItem: false
delegate: iddelegatecomponent
Component
{
id:iddelegatecomponent
Item
{
id: iditem
x: 100
y: 250
width: 400
height: 50
Text
{
id: idtext
text: caption
color: "#FFFFFF"
font.bold: true
font.pixelSize: 26
anchors.verticalCenter: parent.verticalCenter
// anchors.horizontalCenter: parent.horizontalCenter
horizontalAlignment: Text.AlignLeft
}
}
}
}
}
您可以使用索引,每个代理都知道其索引,例如:
ListView{
型号:10
间距:1
焦点:正确
锚定。填充:父级
代表:议程项目{
宽度:parent.width
高度:指数==3?80:40
长方形{
颜色:Qt.dark(Qt.rgba(Math.random(),Math.random(),Math.random(),1.0))
宽度:parent.width
身高:40
正文{
文本:“项目”+索引
颜色:“白色”
anchors.centerIn:父对象
}
}
}
}