有没有办法在ListView中的某个事件上隐藏特定项?
到目前为止,我可以通过设置做到这一点visible,以false和height为代表的零.
但是,如果我将listView中的间距设置为2,例如,此解决方案似乎已被破坏.
解决这个问题的一个技巧可能是将 的间距设置ListView为 0 并在委托本身中实现它。像这样的东西:
ListView{
id: listView
spacing: 0
delegate: Item{
id: itemDelegate
width: parent.width; height: spacingRect.height + actualDelegate.height
Item {id: actualDelegate;} // your actual delegate
Rectangle{ id: spacingRect; height: 2; width: parent.width; color: "transparent"; anchors.top: actualDelegate.bottom}
}
}
Run Code Online (Sandbox Code Playgroud)
这样,当您隐藏委托时,间距也会被隐藏