[英]Hide an item (delegate) inside a ListView QML
我認為正確的方法是使用代理模型過濾掉不應該顯示的元素。 您可以使用QSortFilterProxyModel或實現您自己的QAbstractProxyModel 。 有了它,甚至可以對元素的刪除和添加進行動畫處理。
或者如果您不想接觸 C++ 並且性能不是問題,請使用SortFilterProxyModel
解決這個問題的一個技巧可能是將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}
}
}
這樣,當您隱藏委托時,間距也將被隱藏
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.