如何在ListView的项目之间设置自定义分隔符

Dmi*_*ykh 7 qt qml qt5 qtquick2

有没有办法使用自定义委托作为ListView类似headerfooter属性的每两个连续项之间的分隔符?

BaC*_*Zzo 4

AListView可以分为sections,也称为组。该文档在这里提供了一个很好的示例。

基本上,您定义 a Component,就像定义Header和一样Footer,并将其设置在section.delegate子属性中。在代码中:

ListView {
        id: view
        [...]

        section.property: "size"                    // <--- the splitting property name
        section.criteria: ViewSection.FullString    // <--- specify the way section is created (see the provided link)
        section.delegate: sectionDelegate           // <--- your delegate
    }
Run Code Online (Sandbox Code Playgroud)

  • 我想你应该将分隔符作为 ListView 项目的一部分。部分更倾向于对项目进行分组。 (2认同)