属性

  1. add : Transition
  2. addDisplaced : Transition
  3. cacheBuffer : int
  4. count : int
  5. currentIndex : int
  6. currentItem : Item
  7. currentSection : string
  8. delegate : Component
  9. displaced : Transition
  10. displayMarginBeginning : int
  11. displayMarginEnd : int
  12. effectiveLayoutDirection : enumeration
  13. footer : Component
  14. footerItem : Item
  15. footerPositioning : enumeration
  16. header : Component
  17. headerItem : Item
  18. headerPositioning : enumeration
  19. highlight : Component
  20. highlightFollowsCurrentItem : bool
  21. highlightItem : Item
  22. highlightMoveDuration : int
  23. highlightMoveVelocity : real
  24. highlightRangeMode : enumeration
  25. highlightResizeDuration : int
  26. highlightResizeVelocity : real
  27. keyNavigationEnabled : bool
  28. keyNavigationWraps : bool
  29. layoutDirection : enumeration
  30. model : model
  31. move : Transition
  32. moveDisplaced : Transition
  33. orientation : enumeration
  34. populate : Transition
  35. preferredHighlightBegin : real
  36. preferredHighlightEnd : real
  37. remove : Transition
  38. removeDisplaced : Transition
  39. reuseItems : bool
  40. section
  41. section.criteria : enumeration
  42. section.delegate : Component
  43. section.labelPositioning : enumeration
  44. section.property : string
  45. snapMode : enumeration
  46. spacing : real
  47. verticalLayoutDirection : enumeration

模型model

view所管理的所有的数据都存放在该模型中,以供代理进行显示操作

代理delegate

代理决定如何操作模型中存放的数据

  1. ListView {
  2. id: list
  3. width: 180; height: 200
  4. model: ListModel {
  5. ListElement {
  6. name: "Bill Smith"
  7. number: "555 3264"
  8. }
  9. ListElement {
  10. name: "John Brown"
  11. number: "555 8426"
  12. }
  13. ListElement {
  14. name: "Sam Wise"
  15. number: "555 0473"
  16. }
  17. }
  18. spacing: 20
  19. //当前项高亮
  20. highlight: Rectangle {
  21. color: "lightsteelblue";
  22. }
  23. delegate: Rectangle {
  24. color: "transparent"
  25. width: list.width
  26. height: 20
  27. Text{
  28. id: txt
  29. text: name + ": " + number
  30. }
  31. MouseArea{
  32. anchors.fill: parent
  33. onClicked: {
  34. //修改当前项
  35. currentIndex = index
  36. console.log(index)
  37. }
  38. }
  39. }
  40. }

image.png

拖拽回弹效果

Flickable

interactive : bool 拉动回弹属性

  1. flickableDirection: Flickable.HorizontalFlick //设置回弹方向与使能
  2. delegate: Row {
  3. Text { text: '<b>Name:</b> ' + name; width: 160 }
  4. Text { text: '<b>Number:</b> ' + number; width: 160 }
  5. }

image.png

页眉header\页脚footer

  1. Rectangle{
  2. id: rect
  3. border.width: 2
  4. border.color: "red"
  5. width: 400
  6. height: 200
  7. anchors.centerIn: parent
  8. ListView {
  9. id: list
  10. anchors.fill: rect
  11. // width: 180
  12. // height: 200
  13. header: Rectangle{
  14. width: list.width
  15. height: 20
  16. color:"blue"
  17. }
  18. footer:Rectangle{
  19. width: list.width
  20. height: 20
  21. color: "#22222211"
  22. }
  23. footerPositioning:ListView.OverlayFooter //页脚位置设置
  24. model: ListModel {
  25. ListElement {
  26. name: "Bill Smith"
  27. number: "555 3264"
  28. }
  29. ListElement {
  30. name: "John Brown"
  31. number: "555 8426"
  32. }
  33. ListElement {
  34. name: "Sam Wise"
  35. number: "555 0473"
  36. }
  37. }
  38. spacing: 20
  39. //当前项高亮
  40. highlight: Rectangle {
  41. color: "lightsteelblue";
  42. }
  43. delegate: Rectangle {
  44. color: "transparent" //每项元素的底色
  45. width: list.width
  46. height: 20
  47. Text{
  48. id: txt
  49. text: name + ": " + number
  50. }
  51. MouseArea{
  52. anchors.fill: parent
  53. onClicked: {
  54. //修改当前项
  55. currentIndex = index
  56. console.log(index)
  57. }
  58. }
  59. }
  60. //滑动回弹效果
  61. flickableDirection: Flickable.HorizontalFlick
  62. // delegate: Row {
  63. // Text { text: '<b>Name:</b> ' + name; width: 160 }
  64. // Text { text: '<b>Number:</b> ' + number; width: 160 }
  65. // }
  66. }
  67. }

image.png

section分组显示

  1. Rectangle{
  2. id: rect
  3. border.width: 2
  4. border.color: "red"
  5. width: 400
  6. height: 200
  7. anchors.centerIn: parent
  8. ListView {
  9. id: list
  10. anchors.fill: rect
  11. model: ListModel {
  12. ListElement {
  13. name: "Bill Smith"
  14. number: "555 3264"
  15. size: "small"
  16. }
  17. ListElement {
  18. name: "John Brown"
  19. number: "555 8426"
  20. size: "medium"
  21. }
  22. ListElement {
  23. name: "Sam Wise"
  24. number: "555 0473"
  25. size: "big"
  26. }
  27. }
  28. spacing: 20
  29. //当前项高亮
  30. highlight: Rectangle {
  31. color: "lightsteelblue";
  32. }
  33. //滑动回弹效果
  34. flickableDirection: Flickable.HorizontalFlick
  35. delegate: Row {
  36. Text { text: '<b>Name:</b> ' + name; width: 160 }
  37. Text { text: '<b>Number:</b> ' + number; width: 160 }
  38. }
  39. Component {
  40. id: sectionHeading
  41. Rectangle {
  42. width: rect.width
  43. height: 20
  44. color: "lightsteelblue"
  45. required property string section
  46. Text {
  47. text: parent.section
  48. font.bold: true
  49. font.pixelSize: 20
  50. }
  51. }
  52. }
  53. section.property: "size" //分组排列依据
  54. section.criteria: ViewSection.FullString //控制property对应的size显示方式 是全字符 还是首字符
  55. section.delegate: sectionHeading //控制section的每一个property如何绘制
  56. }
  57. }

image.png